2013-03-30 94 views
1

我通過Facebook API獲取應用程序訪問令牌。通過應用程序向FB用戶發送通知

$app_id = "ID"; 
$app_secret = "SECRET"; 
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&client_secret=".$app_secret."&grant_type=client_credentials"; 
$app_token = file_get_contents($token_url); 

當$ app_token相呼應,下面顯示

access_token=xxxxxxxxxxxxxxxxxxxxxxxx // access token x'ed out for security. 

的 「ID」 等於我的應用程序ID(這我不是夠傻寫)。有一個垂直條將ID與另一個字母數字字符串分開。

我對這方面的API並不是非常有經驗,特別是做涉及應用程序訪問令牌而不是用戶訪問令牌的東西。

所以,當我試圖在PHP腳本發送測試通知

$url = "https://graph.facebook.com/".$fb_user_id."/notifications?href=".$url."&".$app_token; 
$result = file_get_contents($url); 

$結果給我一個錯誤消息,例如:

{"error":{"message":"A user access token is required to request this resource.","type":"OAuthException","code":102}} 

回答

2

由於上https://developers.facebook.com/docs/concepts/notifications/指出,你應該使用HTTP POST請求將通知發送給應用程序的用戶,而不是HTTP GET請求。

+0

還有另一個原因curl> file_get_contents :-) –

+0

嗨,問題:如何獲取通知ID?作爲迴應,您只能獲得成功:true – rayman

+0

@rayman您的應用沒有得到響應中的通知ID。爲什麼你的應用需要處理這個通知ID?如果您願意代表用戶獲得通知,請檢查此答案http://stackoverflow.com/questions/2712443/how-can-i-get-user-notifications-with-the-new-graph- api –

相關問題