2016-07-22 6 views
1

Indian Marketplace Flipkart에서 제공하는 API에서 액세스 토큰을 얻으려고했습니다. 퍼티 SSH에서 컬 코드를 실행하면 액세스 토큰을받을 수 있습니다.하지만 시도 중이면 PHP에서 동일한 문제가 발생하면 400 오류가 발생합니다. SSH에서 사용PHP Curl Basic OAuth 액세스 토큰 받기

코드 (이 작품)

curl -u appid:appsecret https://api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api 

내가 응답

{"access_token":"1111-xxxx-22222","token_type":"bearer","expires_in":4926731,"scope":"Seller_Api"} 

얻을하지만 PHP 컬을 사용하여 같은 일을 달성하려고 할 때 (내가 온라인으로 배운 전용) 내가 400를 얻을 수 오류

PHP 코드 사용 (이 Does'nt 일)

<?php 
$username='appid'; 
$password='appsecret'; 
$url='https://api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api'; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
$output = curl_exec($ch); 
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code 
$info = curl_getinfo($ch); 
curl_close($ch); 

if(curl_errno($ch)){ 
    echo 'Curl error: ' . curl_error($ch); 
} 
print_r($output); 
echo $status_code; 
?> 

잘못된 요청 인 400 (상태 코드)이 아닌 다른 출력이 없습니다.

나는 내가 가까이 있다는 것을 알고, 나는 무엇을 잘못하고 있는지 모른다. 도움을 주시면 감사하겠습니다.

PS : 당신은 우리가 PHP 컬을 사용하여 같은 일을하려고 할 때, 그들은 자신의 문서에 언급 된 URL이 작동하지 않습니다 내가 마지막으로 문제를 해결할 수 있었다 여기 API 문서 도구 https://seller.flipkart.com/api-docs/FMSAPI.html#third-party-application-integration

+1

기다림 - 400 또는 404 오류가 발생합니까? 귀하의 질문에 모두 – WillardSolutions

+0

내 나쁜 단지 400 오류, 나는 그것을 해결합니다. –

+0

이 줄 ->'curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, true);'. '$ curl '이 아닌'$ ch'을 사용하십시오. – WillardSolutions

답변

0

을 찾을 수 있습니다.

URL의 어법은

그래서 URL은되어 있어야 $ URL을 = 'https://api.flipkart.net/oauth-service/oauth/token?grant_type=client_credentials&scope=Seller_Api'PHP의 경우 다른입니다;

및 voila, 내 액세스 토큰을 받았습니다.

추신 : 제발 참을성이없고 주위를 둘러보기 전에 너무 일찍 질문 한 것으로 생각하지 마십시오. 제 2의 날이 똑같은 문제와 싸우고 있습니다. 하지만 오늘은 운이 좋았어.)