2012-04-25 52 views
1

我正在使用以下URL將應用程序生成的請求發送給用戶:如何使用php發送facebook應用程序生成的請求?

https://graph.facebook.com/apprequests/?ids=「。$ userid」。 & message =你好& access_token =「。$ appToken」。 & method = post

如果將$ userid設置爲當前登錄的用戶,此方法正常工作。但我無法向我的朋友發送請求,這是一位應用用戶,上面的代碼會引發以下錯誤:

{「error」:{「message」:「(#2)無法創建任何應用請求」, 「類型」: 「OAuthException」, 「代碼」:2}}

回答

2

這爲我工作:

 
$app_id = YOUR_APP_ID; 
$app_secret = YOUR_APP_SECRET; 

$token_url = "https://graph.facebook.com/oauth/access_token?" . 
"client_id=" . $app_id . 
"&client_secret=" . $app_secret . 
"&grant_type=client_credentials"; 

//your app access token 
$app_access_token = file_get_contents($token_url); 

$apprequest_url ="https://graph.facebook.com/" . 
$your_friend_id . 
"/apprequests?message='some message'&" . 
$app_access_token . "&method=post"; 

$result = file_get_contents($apprequest_url); 
echo $result; 

希望它可以幫助

+0

謝謝哥們..它的工作對我來說: ) – 2012-04-25 05:14:19

相關問題