2016-09-23 5 views
-3
내가 file_get_content와 컬을 교체해야

와 컬 교체 (I 민감한 정보를 삭제 한) : 가 file_get_content

curl -F 'client_id=aaa' \ 
    -F 'client_secret=bbb' \ 
    -F 'grant_type=authorization_code' \ 
    -F 'redirect_uri=http://testtest.altervista.org/instagram/' \ 
    -F 'code=ccc' \ 
    https://api.instagram.com/oauth/access_token 

내가 (이 아무것도 돌려주지 않는)이 있지만 넣은 사람은 아니다 일을 tryed :

$url = 'https://api.instagram.com/oauth/access_token?client_id=aaa&client_secret=bbb&grant_type=authorization_code&redirect_uri=http://testtest.altervista.org/instagram/&code=ccc'; 
print json_decode(file_get_contents($url));  

왜 ?

+0

브라우저에서이 URL을 실행할 때 무엇을 얻고 있습니까? – Exception

+1

당신은 'shell'cURL 명령을 PHP file_get_contents로 대체하고 있습니다 ... 여기서 당신의 진정한 목표는 무엇입니까? – YvesLeBorg

+0

URL 안에 URL이있을 때 내부 URL은 반드시'urlencode()'되어야합니다. 아무 것도 얻지 못하면 오류 로그 또는 적어도 호출에 의해 반환 된 헤더와 상태 코드를 표시하는 것이 도움이됩니다. – DanFromGermany

답변

3

cURL을 file_get_contents로 변경하려는 이유가 확실하지 않지만 최소한 사용하려는 쿼리 문자열을 인코딩해야합니다. 올바른 결과를 얻으려면 http_build_query을 사용할 수 있습니다.

$query = array(
    'client_id' => 'aaa', 
    'client_secret' => 'bbb', 
    'grant_type' => 'authorization_code', 
    'redirect_uri' => 'http://testtest.altervista.org/instagram/', 
    'code' => 'ccc 
); 

$domain = 'https://api.instagram.com/oauth/access_token?' 
$url = $domain . http_build_query($data); 
print json_decode(file_get_contents($url));