使用 FB graph API 发布到多个朋友墙
我有这样的代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您可以使用 API 获取所有好友 ID。然后您可以从该数组中选择 25 个随机索引。
以下是如何执行此操作的示例:
从 JavaScript 数组中获取随机值
然后,您可以迭代(随机) 选择索引,对于每次迭代,您可以执行 FB.api 调用。
graphStreamPublish
可以采用一个参数,即您想要发布到其墙的人的 ID,因此它可能看起来像这样:另外,我认为还可以发送 params 对象作为参数。
最后,这是该函数在上述上下文中的外观:
希望这会有所帮助。祝你有美好的一天!
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: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:
Hope this helps. Have a great day!