【问题标题】:Taking a Facebook array of users - post to friends wall获取 Facebook 用户数组 - 发布到朋友墙
【发布时间】:2014-02-18 02:33:13
【问题描述】:

我有一组 Facebook 用户,它们是使用自定义 Facebook 多选器输出的。

输出是选定用户的列表。

我如何获取这些 ID 号码,然后使用 Facebook API 将消息发布到他们的墙上?

【问题讨论】:

    标签: javascript php facebook facebook-graph-api


    【解决方案1】:

    下面是我之前使用的 PHP 代码 sn-p

    $attachment =  array(
      'from' => $_SESSION['username'],
      'access_token' => $access_token,
      'message' => $message,
      'name' => $title,
      'link' => $url,
      'description' => $description,
      'caption' => $caption,
      'picture' => $img,
      'privacy' => json_encode(array('value' => 'FRIENDS_OF_FRIENDS'))
    );
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$userid.'/feed');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  //to suppress the curl output 
    $result = curl_exec($ch);
    curl_close ($ch);
    

    参考:Facebook Graph API Post

    1. 确保您拥有为您的应用提供的有效访问令牌。

    2. 向您的用户请求“publish_stream”权限。

    编辑:

    这是发布到用户墙上的 JavaScript 方式

    function fb_publish() {
         FB.ui(
           {
             method: 'stream.publish',
             message: 'Message here.',
             attachment: {
               name: 'Name here',
               caption: 'Caption here.',
               description: (
                 'description here'
               ),
               href: 'url here'
             },
             action_links: [
               { text: 'Code', href: 'action url here' }
             ],
             user_prompt_message: 'Personal message here'
           },
           function(response) {
             if (response && response.post_id) {
               alert('Post was published.');
             } else {
               alert('Post was not published.');
             }
           }
        );  
    }
    

    【讨论】:

    • 谢谢 - 但有人有 javascript SDK 示例吗?
    • 感谢 Javascript 编辑。我确实知道如何做到这一点,但是我只是对如何获取一些 ID 号然后将它们推送到您上面的 javascript 代码感兴趣。
    • 让 java 识别 ID 数组的中间部分是我苦苦挣扎的地方!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多