简体   繁体   English

使用PHP中的Graph API发布到Facebook Newsfeed

[英]Posting to Facebook Newsfeed using Graph API in PHP

I am trying to post a message to a user's feed (wall). 我正在尝试将消息发布到用户的供稿(墙)。

I've already got the publish_stream permission and have the user's id ( $fbid ) and access token ( $access_token ), however I am only able to post an empty message to the wall. 我已经具有publish_stream权限,并且具有用户的ID( $fbid )和访问令牌( $access_token ),但是我只能在墙上发布空消息。

This is what the post looks like: 这是帖子的样子:

User Name 用户名

Like · Comment · 12 minutes ago via AppName 赞·评论·12分钟前通过AppName

So basically all the content of the message is missing (everything in the $data variable). 因此,基本上消息的所有内容都丢失了( $data变量中的所有内容)。

This is the code I used: 这是我使用的代码:

include 'facebook.php'; 
$facebook = new Facebook(array(appId =>  $app_id,
                               secret => $app_secret,
                               cookie => true));

$data['post'] = array('access_token' => $access_token,
                      'message' => 'Sign up now',
                      'picture' => 'http://myurl.com/images/pic.jpg',
                      'link' => 'http://myurl.com/',
                      'caption' => 'Get early access to our app'); 

$post_id = $facebook->api('/'.$fbid.'/feed/', 'post', $data);

What am I missing? 我想念什么? Why is $data content not displayed in the post? 为什么$data内容未显示在帖子中?

The problem is with $data['post'] you are not sending correct data to the API. 问题在于$data['post']您没有向API发送正确的数据。

Change it to $data I am not really sure why you have the 'post' part in there for. 将其更改为$data我不太确定为什么要在其中添加“发布”部分。

If you need it in the format $data['post'] then change your API call to read 如果您需要$data['post']格式,则将您的API调用更改为read

$post_id = $facebook->api('/'.$fbid.'/feed/', 'post', $data['post']);

See example at https://gist.github.com/3378724 请参见https://gist.github.com/3378724上的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM