2013-01-22 3 views
0

문제를 해결하려면 도움이 필요합니다. 내가 시도가 사용자에 대한 데이터를 얻을 때이 오류가 발생 토큰 가지고 얼마 후이가 실행그래프 API - 스트림을 열지 못했습니다 : HTTP 요청에 실패했습니다! HTTP/1.0 400 잘못된 요청

A PHP Error was encountered 

Severity: Warning 

Message: file_get_contents(https://graph.facebook.com/me?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request 

코드 :

$url = "https://graph.facebook.com/me?access_token=".$token; 
$dados = @json_decode(file_get_contents($url)); 

가 어떻게이 문제를 해결할 수 있습니까? 왜 이런 일이 일어 났습니까?

많은 검색을했지만 해결책을 찾지 못했습니다. 누군가 제발 도와주세요.

감사합니다.

+0

액세스 토큰을 [디버거] (https://developers.facebook.com/tools/debug)에 붙여 넣으십시오. 유효하고 * 사용자 * 액세스 토큰입니까? – cpilko

답변

0

는 내가 PHP SDK를 사용하는 것이 좋습니다 : https://github.com/facebook/facebook-php-sdk

잠깐만 실례 또한 올바른 로그인 처리를 포함하여, "사용"아래로 스크롤하면 몇 가지 예제 코드입니다. 이를 통해 액세스 토큰에 대해 실제로 생각해 볼 필요는 없습니다. 모두 백그라운드에서 발생합니다. 또한 확장하기를 원하는 경우 액세스 토큰은 최대 2 시간 동안 만 유효합니다. PHP SDK의 "setExtendedAccessToken"기능을 사용하여 최대 60 일까지 확장 할 수 있습니다.

0

토큰을 urlencode()하여 file_get_contents()에 전달하십시오. 이것은 효과가있을 수 있습니다.

file_get_contents will only work if you have allow_url_fopen = 1 in your php.ini 

위와 같은 원격 파일 액세스의 경우 PHP가 제공하는 cURL 함수를 사용해보십시오.

function url_get_contents ($Url) { 
    if (!function_exists('curl_init')){ 
     die('CURL is not installed!'); 
    } 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $Url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $output = curl_exec($ch); 
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get the code of request 
    curl_close($ch); 

    if($httpCode == 400) 
     return 'No donuts for you.'; 

    if($httpCode == 200) //is ok? 
     return $output; 


} 
관련 문제