使用 FB graph API 发布到多个朋友墙

发布于 2024-10-14 05:25:16 字数 694 浏览 1 评论 0原文

我有这样的代码:

       function graphStreamPublish(){


var params = {};
params['message'] = '';
params['name'] = '';
params['description'] = '';
params['link'] = '';
params['picture'] = '';
params['caption'] = '';

FB.api('/me/feed',  'post', params, function(response) {
  if (!response || response.error) {
   alert('Error occured');
  } else { }

效果很棒,当我将 /me/feed 更改为 /MY_FRIENDS_ID/feed 时,它会发布到我的墙或我朋友的墙上

但我想要的是一次随机发布到 25 个朋友(只需单击一下)选择我的朋友 ID。

有没有 PHP 代码或任何可以做到这一点的东西?例如,访问我的朋友 ID 并将其提取到某种文件中,然后将它们放入 /FRIENDS_ID/feed 代码中?

对不起我的英语。我昨天刚开始学习 Facebook 应用程序,抱歉,如果我听起来太业余了。

我听说有一些名为“循环”的 php 代码,它可以工作......如果有人可以帮助我,请帮助我。我将不胜感激!

I have this code:

       function graphStreamPublish(){


var params = {};
params['message'] = '';
params['name'] = '';
params['description'] = '';
params['link'] = '';
params['picture'] = '';
params['caption'] = '';

FB.api('/me/feed',  'post', params, function(response) {
  if (!response || response.error) {
   alert('Error occured');
  } else { }

which works awesome and it posts to my wall or my friend's wall when I change /me/feed to /MY_FRIENDS_ID/feed

But what I want is to post to 25 friends at a time (with one click) by randomly selecting my friends IDs .

Is there any PHP code or anything that can do that? For example accessing and extracting my friends IDs to a some kind of file and then putting them in to the /FRIENDS_ID/feed code?

Sorry for my english. I just started to learn facebook apps yesterday, sorry if I sound too amateur.

I heard there is some php code called 'loop' and it works... Please if anyone can help me. I would appreciate that!

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

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

发布评论

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

评论(1

暖伴 2024-10-21 05:25:16

首先,您可以使用 API 获取所有好友 ID。然后您可以从该数组中选择 25 个随机索引。

以下是如何执行此操作的示例:
从 JavaScript 数组中获取随机值

然后,您可以迭代(随机) 选择索引,对于每次迭代,您可以执行 FB.api 调用。

graphStreamPublish 可以采用一个参数,即您想要发布到其墙的人的 ID,因此它可能看起来像这样:

function graphStreamPublish(targetID) {

    var params = {};
    params['message'] = '';
    params['name'] = '';
    params['description'] = '';
    params['link'] = '';
    params['picture'] = '';
    params['caption'] = '';

    FB.api('/' + targetID +'/feed',  'post', params, function(response) {
        if (!response || response.error) {
            alert('Error occured');
        } else {});

另外,我认为还可以发送 params 对象作为参数。

最后,这是该函数在上述上下文中的外观:

for(i = 0; i < selectedFriendIDs.length; i++)
    graphStreamPublish(selectedFriendIDs[i]);

希望这会有所帮助。祝你有美好的一天!

First, you can get all friends IDs using the API. You can then select 25 random indices from that array.

Here is an example of how to do it:
Getting a random value from a JavaScript array

You can then iterate through the (randomly) selected indices, and for each iteration, you can do the FB.api call.

The graphStreamPublish could take one parameter, which is the ID of the person whose wall you want to post to, so it could look something like this:

function graphStreamPublish(targetID) {

    var params = {};
    params['message'] = '';
    params['name'] = '';
    params['description'] = '';
    params['link'] = '';
    params['picture'] = '';
    params['caption'] = '';

    FB.api('/' + targetID +'/feed',  'post', params, function(response) {
        if (!response || response.error) {
            alert('Error occured');
        } else {});

Also, I'm thinking the params object can also be sent as a parameter.

And finally, here's how this function would look in the mentioned context:

for(i = 0; i < selectedFriendIDs.length; i++)
    graphStreamPublish(selectedFriendIDs[i]);

Hope this helps. Have a great day!

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