简体   繁体   English

使用PHP发布到用户墙

[英]Posting to a user's wall using PHP

OK this has been keeping me busy for 2 days now and I'm banging my brains out now. 好吧,这已经让我忙了两天了,现在我正在全力以赴。 I've posted it on forums, asked friends, googled it extensively and looked on stackoverflow. 我已经将其发布在论坛上,询问朋友,对其进行了广泛的Google搜索,并研究了stackoverflow。 I'm not the first to post this question but I couldn't find the answer among the responses so that's why I'm creating this new question. 我不是第一个提出这个问题的人,但是我在答案中找不到答案,所以这就是我创建这个新问题的原因。

this is what I'm trying to do : - I want to post a message to a user's wall as a Facebook-app in PHP. 这就是我要尝试的操作:-我想将消息作为PHP中的Facebook应用程序发布到用户的墙上。 - I want to do this server-to-server, so without the dialog box and any user-interaction (he could be mowing the lawn at that moment for all I care) - This user has granted permission to my app, these permissions are: 1) manage_pages, 2) publish_stream, 3) read_stream - I'm using the PHP Facebook SDK - this is my code: -我要在服务器与服务器之间进行此操作,因此,在没有对话框和任何用户交互的情况下(我可能会在那时修剪草坪)-该用户已授予我的应用程序权限,这些权限是:1)manage_pages,2)publish_stream,3)read_stream-我正在使用PHP Facebook SDK-这是我的代码:

/* Facebook */ 
$facebook = new Facebook(array(
    'appId'  => FACEBOOK_APP_ID,
    'secret' => FACEBOOK_APP_SECRET
));
/* string */ 
$accessToken = $facebook->getAccessToken();
/* Array<string> */ 
$postFields = array("message"=>"test2", "access_token"=>$accessToken);

$facebook->api('/{the-id-of-the-facebook-user}/feed','post',$postFields);

this is the issue : I keep getting the following error : (#200) The user hasn't authorized the application to perform this action. 这是问题:我不断收到以下错误消息:(#200)用户尚未授权应用程序执行此操作。

This is a bullshit-message cause the user HAS authorized my app (That user also happens to be me and I checked all the permissions under apps, they're fine). 这是胡扯的消息,原因是用户已授权我的应用程序(该用户也恰好是我,我检查了应用程序下的所有权限,它们很好)。

Any suggestions would be greatly appreciated cause I don't know where to look anymore. 任何建议将不胜感激,因为我不知道在哪里看了。 I know others posted this question before but the answers weren't satisfying. 我知道其他人以前曾发布过此问题,但答案并不令人满意。 Thanks a lot in advance. 非常感谢。

An app isn't allowed to post to a user's wall. 不允许将应用发布到用户的墙上。 You can only post to the wall as the user or as a different user (ie user-to-user). 您只能以用户或其他用户(即用户到用户)的身份张贴到墙上。 If you want to notify the user of something, you should use the app-to-user Requests API instead. 如果您想通知用户某些信息,则应改用“应用程序对用户的请求” API。

I couldn't figure out what caused the error. 我不知道是什么导致了错误。 I tried a multitude of angles. 我尝试了多种角度。 In some cases I did manage to post something to the wall because the api returned an ID for the post which I could enter into the the browser to view the post (www.facebook.com/{the-id-of-the-post}). 在某些情况下,我确实设法在墙上张贴了一些东西,因为api返回了该帖子的ID,我可以将其输入浏览器中以查看该帖子(www.facebook.com/{the-id-of-the-post }。

The strange thing is however, that this post didn't appear on the timeline but on a separate page. 然而,奇怪的是,该帖子并未出现在时间轴上,而是出现在单独的页面上。 This page didn't have the user-profile at the top as is the case with a normal Facebook page. 与普通的Facebook页面一样,该页面的顶部没有用户个人资料。 It also had a storyID parameter in the querystring. 它在查询字符串中也有一个storyID参数。 I couldn't figure out on what page I was and why it didn't just appear on the timeline. 我不知道自己在哪个页面上以及为什么它不仅仅出现在时间轴上。

The Facebook-page I was trying to post to was a Company-page. 我试图发布到的Facebook页面是公司页面。 But it wasn't attached to a 'normal' Facebook-page (of a person) as usually is the case. 但这并不像通常那样附在“正常的”(某人)Facebook页面上。 Eventually I did manage to post to the page of a page belonging the a 'normal' facebookpage. 最终,我确实设法发布到属于“正常” facebook页面的页面的页面。 So in most cases my code works now. 因此,在大多数情况下,我的代码现在可以运行了。 Rest to say that there's still much to improve in the Facebook SDK, it's documentation and that of http://developers.facebook.com . 不用说,Facebook SDK,文档和http://developers.facebook.com的文档仍有很多改进之处。 It's not very clear how to perform certain operations. 还不清楚如何执行某些操作。 I spent a lot of time once on a WP7 app for a Facebook-feature and now I spent at least 4 days to get this to work for this website. 我花了很多时间在WP7应用程序上使用Facebook功能,现在我花了至少4天的时间使它在该网站上可用。 I've decided to write my own SDK and expand it in the future. 我决定编写自己的SDK并在将来进行扩展。

Thanks to everyone for your time and help. 感谢大家的时间和帮助。 Stackoverflow rocks! Stackoverflow令人震惊!

If the feed you want to post is from the same user who has granted permissions you can put me instead of {the-id-of-the-facebook-user} . 如果您要发布的Feed来自授予权限的同一用户,则可以放me而不是{the-id-of-the-facebook-user} I just tried this and it worked: 我只是尝试了一下,它起作用了:

$facebook->api(
    '/me/feed/',
    'post',
    array(
    'message' => "my message"
));

No need to post access_token. 无需发布access_token。 And the permissions the user gave were only publish_actions 用户授予的权限只是publish_actions

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

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