2012-02-03 4 views
2

イムはEROR [function.file-getを-内容]開発者がのFacebookアプリケーションの要求発行

$token_url = "https://graph.facebook.com/oauth/access_token?" . 
    "client_id=" . facebook::getConfig('appId') . 
    "&client_secret=" . facebook::getConfig('secret') . 
    "&grant_type=client_credentials"; 
$app_access_token = file_get_contents($token_url); 
$user_id = "100002758712176"; 
$apprequest_url = "https://graph.facebook.com/". 
    $user_id . 
    "/apprequests?message='test string'&" . 
    $app_access_token . "&method=post"; 
$result = file_get_contents(urlencode($apprequest_url)); 
echo "App Request sent? ". $result; 

を元ウェブページの例をテストしようとしてました! HTTP/1.1 400 Bad Request ブラウザで$ apprequest_urlを使用するとすべて動作します。問題はどこだ ?

+0

はあなたですあなたのアプリケーションにログインしたFacebookのユーザーですか?ユーザーがアプリを認証した後にのみ、アクセストークンをリクエストできます。 – Lix

答えて

0

は、まずあなたがURLに送信された文字列をURLENCODE必要があります。

$apprequest_url = "https://graph.facebook.com/" . $user_id . "/apprequests?message=" . urlencode('test string') . "&" . $app_access_token . "&method=post"; 
0

何かが奇妙に見える...あなたはURL全体をコードしているよう

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

がまず第一に、それが見えます。第二に、あなたのURL文字列は$ app_access_tokenが含まれていますが、それはのparamキーにバインドされていません...「というメッセージ」をコードし、あなたのURL stirngに「access_tokenは」を追加することのみURLをしようとする場合があります:

$message = urlencode('test string'); 
$apprequest_url = "https://graph.facebook.com/$user_id/apprequests?"; 
$apprequest_url .= "message=$message&access_token=$app_access_token&method=post"; 
関連する問題