12

アプリを作成しました。新しいグラフAPIを使用して、友達のウォールの1つにメッセージを投稿したいと思います。これは実行可能ですか?

私はすでにoAuthとGraph-apiを使用して、すべての友達のリストを取得しています。http://developers.facebook.com/docs/apiのAPIは、フィードを読むためにcURL https://graph.facebook.com/[userid]/feedを教えてくれますが、メッセージを投稿する方法も教えてくれます。

curl -F 'access_token=[...]' -F 'message=Hello, Arjun. I like this new API.' https://graph.facebook.com/arjun/feed

もちろん、これは機能しません!そして、その理由がわかりません。

これが私のPHPコードです:

require_once 'facebook.php'; // PHP-SDK downloaded from http://github.com/facebook/php-sdk
$facebook = new Facebook(array(appId=>123, secret=>'secret'));
$result = $facebook->api(
        '/me/feed/',
        array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..')
);

このコードはエラーをスローせず、access_tokenが正しいことを知っています(そうでなければ、$ facebook-> api('/ me?access_token='。$this-> access_token);を実行してユーザーオブジェクトを取得できませんでした。

Graph-apiを使用してメッセージを投稿した人はいますか?それなら私はあなたの助けが必要です!:-)

4

7 に答える 7

18

さて、私はついにこれを解決しました。あなたの助けのためにphpfourに感謝します:-)

最初:私のconnection-urlは次のようになります( "publish_stream"を使用):

$connectUrl = $this->getUrl(
  'www',
  'login.php',
  array_merge(array(
    'api_key'         => $this->getAppId(),
    'cancel_url'      => $this->getCurrentUrl(),
    'req_perms'       => 'publish_stream',
    'display'         => 'page',
    'fbconnect'       => 1,
    'next'            => $this->getCurrentUrl(),
    'return_session'  => 1,
    'session_version' => 3,
    'v'               => '1.0',
  ), $params)
);

2番目; 経由でFacebookに投稿しようとしました

$result = $facebook->api(
    '/me/feed/',
    array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..')
);

ただし、これを行う正しい方法は、もう1つのパラメーター(「post」)を含めることです。

$result = $facebook->api(
    '/me/feed/',
    'post',
    array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..')
);
于 2010-05-12T12:40:06.573 に答える
6

フィードに書き込むには、「publish_stream」拡張権限が必要です。それらの完全なリストは次のとおりです:http://developers.facebook.com/docs/authentication/permissions

拡張権限を取得するには、次の方法で認証トークンを取得します。

https://graph.facebook.com/oauth/authorize?
client_id=...&
redirect_uri=http://www.example.com/callback&
scope=publish_stream
于 2010-05-06T19:57:59.090 に答える
1

chfに加えて、

投稿後:

$getLinkToken='https://graph.facebook.com/oauth/access_token'.
              '?client_id=YOUR_APPID'.
              '&redirect_uri=YOUR_SITE'.
              '&client_secret=YOUR_SECRET'.
              '&code=CODE_KEY';

私は応答を得ました:

 https://graph.facebook.com/oauth/access_token?
    client_id=xxxxxxxxxxxxxx
    &redirect_uri=myurl
    &client_secret=xxxxxxxxxxxxxx
    &code=xxxxxxxxxxxxxx

誰でもないaccess_tokenclient_secretまたはコード

$facebook->api( '/YOUR_APPID/feed/', 'post', 
array('access_token' => $this->access_token,
'message' => 'Playing around with FB Graph..'));
于 2010-08-23T05:31:11.780 に答える
1

リンクが言うように:ここにリンクの説明を入力してください

<?php 
  $app_id = "YOUR_APP_ID";
  $app_secret = "YOUR_APP_SECRET";
  $my_url = "YOUR_POST_LOGIN_URL"; 
  $code = $_REQUEST["code"];
  if(empty($code)) {
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
    . $app_id . "&amp;redirect_uri=" . urlencode($my_url) . "&amp;scope=email";
    echo("<script>top.location.href='" . $dialog_url . "'</script>");
  }
  $token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&amp;redirect_uri=" . urlencode($my_url)
    . "&amp;client_secret=" . $app_secret
    . "&amp;code=" . $code;
  $access_token = file_get_contents($token_url);
  $graph_url="https://graph.facebook.com/me/permissions?".$access_token;
  echo "graph_url=" . $graph_url . "<br />";
  $user_permissions = json_decode(file_get_contents($graph_url));
  print_r($user_permissions);
?>
于 2011-05-06T12:06:42.953 に答える
1

明確にするために、ここでの「post」は、GET/POSTのようにHTTPメソッドを指します。https://github.com/facebook/php-sdk/blob/master/src/base_facebook.phpを参照してください:protected function _graph($ path、$ method ='GET'、$ params = array())

$ result = $ facebook-> api('/ me / feed /'、'post'、array('access_token' => $ this-> access_token、'message' =>'FBグラフで遊んでいます..')) ;

于 2011-08-03T16:43:09.380 に答える
0

以下のコードを使用する代わりに

[facebook dialog:@"feed"
 andParams:params 
 andDelegate:self]; 

次のソリューションを使用します

[facebook requestWithGraphPath:@"me/feed" andParams:params andHttpMethod:@"POST" andDelegate:self];
于 2012-11-28T06:52:32.950 に答える
0

それはアクセスを取得するための古い方法です。GRAPHでは、最初に次のコードキーを生成しました。

$getLinkCode ='https://graph.facebook.com/oauth/authorize'.
              '?client_id=YOUR_APPID'.
              '&redirect_uri=YOUR_SITE'.
              '&scope=publish_stream';

これで、コードキーができたら、リンクからaccess_tokenを生成できます。

$getLinkToken='https://graph.facebook.com/oauth/access_token'.
              '?client_id=YOUR_APPID'.
              '&redirect_uri=YOUR_SITE'.
              '&client_secret=YOUR_SECRET'.
              '&code=CODE_KEY';

しかし、このaccess_tokenは、アプリケーションではなくユーザーとしてメッセージを投稿します...なぜですか?!

アプリケーションウォールの使用に関する投稿が必要な場合:

$facebook->api( '/YOUR_APPID/feed/', 'post', array('access_token' => $this->access_token, 'message' => 'Playing around with FB Graph..'));
于 2010-06-19T01:15:13.390 に答える