使用图形 API 在朋友的墙上发帖

发布于 2024-10-29 02:49:40 字数 581 浏览 0 评论 0原文

在朋友墙上发布消息,图形 API。 我拥有正在使用该应用程序的用户的publish_stream扩展权限。

如果我想在墙上张贴某些内容,该代码就可以工作。

有没有什么方法可以在墙上张贴或向特定用户的所有朋友发送消息?

请帮忙谢谢!!

以下是代码,但它不起作用。

 $friends = $facebook->api('/me/friends');
    foreach($friends['data'] as $friend){
            $friendsUserId = $friend['id'];
            echo $friendsUserId . "</br>";
            $result = $facebook->api('/$friendsUserId/feed', 'POST', array(                
                    message' => 'Test Message'                ));
            print_r($result);
        }

Posting a message on friend's wall, graph API.
i have the publish_stream extended permission of the user, who is using the application.

the code workds if i want to post sth on my wall.

is there any method to post on wall or send message to all the friends of a particular user??

please help thanks!!

following is the code, but it is not working.

 $friends = $facebook->api('/me/friends');
    foreach($friends['data'] as $friend){
            $friendsUserId = $friend['id'];
            echo $friendsUserId . "</br>";
            $result = $facebook->api('/$friendsUserId/feed', 'POST', array(                
                    message' => 'Test Message'                ));
            print_r($result);
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

本王不退位尔等都是臣 2024-11-05 02:49:40

这也许是实现它的方法。(未经测试,但我在我的应用程序中使用类似的东西。)

$friends = $facebook->api('/me/friends');

    foreach($friends['data'] as $friend) {
        $facebook->api('/$friend['id']/feed', 'post', array(
                  'message' => 'just a test message',
                  'link' => 'http://site.com',
                  'name' => 'just a test name',
                  'caption' => 'just a test caption',
                  'description' => 'just a test description',
          ));

}

这是使用 PHP API

This would perhaps be the way to do it.. (Untested, but I use something similar for my app.)

$friends = $facebook->api('/me/friends');

    foreach($friends['data'] as $friend) {
        $facebook->api('/$friend['id']/feed', 'post', array(
                  'message' => 'just a test message',
                  'link' => 'http://site.com',
                  'name' => 'just a test name',
                  'caption' => 'just a test caption',
                  'description' => 'just a test description',
          ));

}

This is using the PHP API.

小镇女孩 2024-11-05 02:49:40

我只是做了一些测试,并且拥有用户的权限,我确实可以通过 php api 在用户的朋友墙上发布:

$facebook->api('/[FRIEND_ID]/feed', 'post', array(
          'message' => 'test message',
          'link' => 'http://google.com',
          'name' => 'test name',
          'caption' => 'test caption',
          'description' => 'test long description',
      ));

I just did a little testing, and having the permissions of the user, I could indeed post on the user's friends walls via the php api:

$facebook->api('/[FRIEND_ID]/feed', 'post', array(
          'message' => 'test message',
          'link' => 'http://google.com',
          'name' => 'test name',
          'caption' => 'test caption',
          'description' => 'test long description',
      ));
私藏温柔 2024-11-05 02:49:40

publish_stream 权限只允许您在该特定用户的墙上发布内容 - 您不能在他所有朋友的墙上发布内容。

以这种方式思考 - 假设您没有授权应用程序在您的 Facebook 墙上发布任何内容,但仅仅因为您的一个朋友授予了对他的墙的访问权限 - 它会自动授予该应用程序在他所有的墙上发布的权限朋友们。

编辑

拉胡尔,昨天晚上我尝试以自己的身份登录并通过我的应用程序在我的一位朋友的墙上发布消息,令人惊讶的是它有效。我的错误印象是你不能这样做。我很抱歉。

但我仍然无法弄清楚这一点。让我解释一下,

1) I have my real facebook lets call it abc and a test facebook account xyz which I've added as my friend to abc
2) I login into my app using my abc faceboook account and publish a message on the wall of my friend xyz
3) Now I login to facebook.com as abc and it shows on my news feed the message that I published on xyz's wall. When I click on xyz's profile - the message shows up on his wall too. So far so good
4) Now I log out of facebook.com as abc and log back in as xyz. But now I dont see the message that was posted through the app on the wall of xyz.

我不知道是否有任何延迟,但我已经等了 30 分钟,但仍然没有出现。但当我以 abc 身份登录时,它继续显示。

我希望你能理解我在这里想表达的意思。
我使用了与您相同的代码 - 所以您可以尝试上述场景,看看您是否遇到类似的情况

谢谢

The publish_stream permission only allows you to publish content on that particular users wall - you cannot post on the wall of all his friends.

Think about it this way - say you have not authorized an application to post anything on your facebook wall but just because one of your friends has given access to his wall - it automatically does not give the application access to publish on the wall of all his friends.

EDIT

Rahul, I tried yesterday night to login as myself and post a message on the wall of one of my friends through my app and surprisingly it worked. I was under the wrong impression that you could not do that. My apologies.

But I'm still not able to figure this out. Let me explain

1) I have my real facebook lets call it abc and a test facebook account xyz which I've added as my friend to abc
2) I login into my app using my abc faceboook account and publish a message on the wall of my friend xyz
3) Now I login to facebook.com as abc and it shows on my news feed the message that I published on xyz's wall. When I click on xyz's profile - the message shows up on his wall too. So far so good
4) Now I log out of facebook.com as abc and log back in as xyz. But now I dont see the message that was posted through the app on the wall of xyz.

I dont know if there is any kind of delay but I've waited 30 mins but still its not there. But it continues to show when I log in as abc.

I hope you understand what I'm trying to convey here.
I've used the same piece of code like yours - so can you try the above scenarios and see if you experience something similar

Thanks

眼睛会笑 2024-11-05 02:49:40

Gubloo 的答案很接近。

发布到朋友的墙上是完全可能的,但需要注意的是,所述朋友也必须在某个时刻经历过“权限”对话。这意味着,您的应用程序的用户将能够在您的应用程序的其他用户的墙上发布内容。

我会给你 iPhone 代码,因为我不懂 php,并且想象你会明白要点。只需将“me”替换为您要发布的内容的 UID(页面或朋友的个人资料)即可。

[_facebook requestWithGraphPath:@"/me/feed"
andParams: 参数
andHttpMethod:@"POST"
andDelegate:self];

我实际上很好奇,这是否会让用户能够在任何使用该应用程序的人的墙上发帖,而不仅仅是他的朋友。

Gubloo's answer is close.

Posting to a friend's wall is completely possible, but with one caveat, said friend must have also gone through the 'Permissions' dialogue at some point. Meaning, users of your application will be able to post to the wall's of other users of your application.

I'm going to give you the iPhone code, because I don't know php and imagine you'll get the gist. Just replace 'me' with the UID of whatever you are trying to post to, be a page, or a Friend's profile.

[_facebook requestWithGraphPath:@"/me/feed"
andParams:params
andHttpMethod:@"POST"
andDelegate:self];

I'm actually curious to know if this would give the user the ability to post on the wall of anyone who uses the application, and not just his friends.

若言繁花未落 2024-11-05 02:49:40

$friends = $facebook->api('/me/friends');

foreach($friends['data'] as $friend) {
    $facebook->api('/$friend['id']/feed', 'post', array(
              'message' => 'just a test message',
              'link' => 'sample link.com',
              'name' => 'just a test name',
              'caption' => 'just a test caption',
              'description' => 'just a test description',
      ));

}
上面的代码对我也有用
感谢您的帖子

$friends = $facebook->api('/me/friends');

foreach($friends['data'] as $friend) {
    $facebook->api('/$friend['id']/feed', 'post', array(
              'message' => 'just a test message',
              'link' => 'sample link.com',
              'name' => 'just a test name',
              'caption' => 'just a test caption',
              'description' => 'just a test description',
      ));

}
Above code work for me tooooo
Thanks for the post

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文