如何使用 FB Graph 在提要(墙)上发布消息 [英] Howto use FB Graph to post a message on a feed (wall)

查看:35
本文介绍了如何使用 FB Graph 在提要(墙)上发布消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个应用程序,现在我想使用新的 Graph API 在我的一个朋友墙上发布一条消息.这能行吗?

I have created an app, and now i want to post a message on one of my friends wall with use of the new Graph API. Is this do-able?

我已经在使用 oAuth 和 Graph-api 来获取我所有朋友的列表.http://developers.facebook.com/docs/api 上的 API 告诉我 cURLhttps://graph.facebook.com/[userid]/feed 阅读feed,但它也告诉我如何发布消息:

I am already using oAuth and the Graph-api to get a list of all my friends. The API at http://developers.facebook.com/docs/api tells me to cURL https://graph.facebook.com/[userid]/feed to read the feed, but it also tells me howto post a message:

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

这当然不行!我不知道为什么..

Ofcourse this doesn't work! And I can't find out why..

这是我的 PHP 代码:

Here are my PHP-code:

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); 来获取我的用户对象.

This code does not throws any error, and I know my access_token are correct (otherwise i could't run $facebook->api('/me?access_token='.$this->access_token); to get my userobject.

有没有人使用 Graph-api 成功发布消息?那么我需要你的帮助!:-)

Have anyone out there sucsessfully posted a message using Graph-api? Then i need your help! :-)

推荐答案

好的,我终于解决了这个问题.感谢 phpfour 的帮助:-)

Okay, I finally solved this. Thanx to phpfour for your help :-)

首先:我的连接 url 看起来像这样(带有publish_stream"):

First: My connection-url looks like this (with "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)
);

第二;我试图通过

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

但正确的做法是多包含一个参数('post'):

But the correct way to do this is include one more parameter ('post'):

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

这篇关于如何使用 FB Graph 在提要(墙)上发布消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆