如何使用 FB Graph 在提要(墙)上发布消息

Howto use FB Graph to post a message on a feed (wall)(如何使用 FB Graph 在提要(墙)上发布消息)
本文介绍了如何使用 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 在提要(墙)上发布消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)