2011-04-07 4 views
0

난 내 자신의 벽에 게시하기 전에 인증해야하는 것은 내 코드는 페이스 북 응용 프로그램 인증 - 그래서 여기, PHP

function get_app_token($appid, $appsecret) 
{ 
$args = array(
'grant_type' => 'client_credentials', 
'client_id' => $appid, 
'client_secret' => $appsecret 
); 

$ch = curl_init(); 
$url = 'https://graph.facebook.com/oauth/access_token'; 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, false); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $args); 
$data = curl_exec($ch); 

return json_encode($data); 
} 

$token = get_app_token($appid, $appsecret); 
$attachment = array('message' => '', 
     'access_token' => $token, 
       'name' => 'Attachment Name', 
       'caption' => 'Attachment Caption', 
       'link' => 'http://apps.facebook.com/xxxxxx/', 
       'description' => 'Description .....', 
       'picture' => 'http://www.google.com/logo.jpg', 
       'actions' => array(array('name' => 'Action Text', 
            'link' => 'http://apps.facebook.com/xxxxxx/')) 
       ); 

$result = $facebook->api('/me/feed/', 'post', $attachment); 

내가 오류 OAuthException , 잘못된 OAuth 액세스 토큰 서명을 받고 있습니다.

+0

가능한 중복 (http://stackoverflow.com/questions/5126665/need- help-on-post-on-user-wall) – ifaour

+0

위에서 게시 한 링크를 통해 시작할 수 있습니다. "응용 프로그램 액세스 토큰"을 요청하고 있습니다! 이것은 사용자를 대신하여 작업을 수행하는 데 사용되지 않습니다! – ifaour

답변

0

facebook 개체의 세션 배열에서 직접 access_token을 얻을 수 있습니다.

$session = $facebook->getSession(); 
$session['access_token']; 

물론 허가를 받아야합니다. 세션이 설정되지 않은 경우 loginUrl

$facebook->getLoginUrl(array('req_perms' => 'email,read_stream,publish_stream')); 
// this will return url for your authorization 

으로 리디렉션하고 필요한 사용 권한을 요청해야합니다.

+0

내가 모든 코드를 보여 주면 plz를 고칠 수 있습니까? – Sourav

-1

client_credentials 액세스 토큰은 /me에 액세스 할 수 없으며 (이 경우 사용자는 누구와 연결 되나요?) 액세스 권한은 말할 것도없이 액세스 토큰은 사용자에게 연결됩니다. 응용 프로그램의 통계 데이터를 얻는 것처럼 응용 프로그램 수준의 그래프 API 호출에만 사용됩니다. $token

+0

문제를 해결하도록 도와 줄 수 있습니까? – Sourav

+0

oauth 흐름을 완전히 다시 작성해야합니다. – ceejayoz

+0

FB 앱에 새로운 기능이있어서 오늘부터 시작 했으므로 코드가 필요합니다. | – Sourav

0

가치 당신은 access_token 매개 변수에 직접 $token 값을 전달할 수 없습니다 access_token=<YOUR_ACCESS_TOKEN>

입니다. 이 의지는 그 일을하는 데 도움이

$token = get_app_token($appid, $appsecret); 
$access_token = split('=',$token); 
$attachment = array(
        'message' => '', 
        'access_token' => $access_token[1], 
        'name' => 'Attachment Name', 
        'caption' => 'Attachment Caption', 
        'link' => 'http://apps.facebook.com/xxxxxx/', 
        'description' => 'Description .....', 
        'picture' => 'http://www.google.com/logo.jpg', 
        'actions' => array(array('name' => 'Action Text', 
           'link' => 'http://apps.facebook.com/xxxxxx/')) 
      ); 

희망 ... :)

[사용자 벽에 게시에 도움이 필요합니다]의
+0

당신의 도움에 감사하지만 그것도 같은 오류를 반환, plz 내 코드 http://www.web-shine.in/tutorials/fb/code.txt 봐 봐 – Sourav

+0

'토큰'의 가치는 무엇입니까? –