首页 文章

如何通过Open Graph标签朋友使用facebook api taggable_friends

提问于
浏览
2

如何通过Open Graph标签朋友使用facebook api taggable_friends . 我的应用程序使用taggable_friends api我想在朋友墙上标记我的朋友 . 使用提及朋友或标记朋友https://developers.facebook.com/docs/opengraph/using-actions/v2.0#capabilities

我使用Open Graph doc Step by Step尝试但是给我“你,或者这个应用程序的Open Graph Test用户,必须至少发布过一次这个动作”如何设置?

https://developers.facebook.com/docs/apps/review/opengraph

2 回答

  • 9

    在FB javascript sdk上,

    - fb dashboard -> Open Graph*

    • 创建一个故事

    • 列表项确保在操作类型中启用_tags,-user messages,-place等'capabilities'功能 .

    • *在你的js

    1. call the js sdk

    window.fbAsyncInit = function() {
        FB.init({
          appId      : {YOUR_APP_ID} , // App ID
          version: 'v2.0',
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          oauth      : true, // enable OAuth 2.0
          xfbml      : true  // parse XFBML
        });
      };
    
    
    
        // Load the SDK Asynchronously
          (function(d){
             var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
             js = d.createElement('script'); js.id = id; js.async = true;
             js.src = "//connect.facebook.net/en_US/sdk.js";
             d.getElementsByTagName('head')[0].appendChild(js);
           }(document));
        }
    

    3. Login into FB asking with these scopes

    function Login()
        {
    
            FB.login(function(response) {
               if (response.authResponse) 
               {
                    console.log(response.authResponse); // Get User Information.
    
                } else
                {
                 console.log('Authorization failed.');
                }
             },{scope: 'user_friends, publish_actions, status_update, read_stream, manage_friendlists'});// ' user_interests, user_likes, etc.. '
    
        }
    

    4. Get the logged user taggable_friends with a function such as:

    var  var friendsIDarray = [];
    var user_friend_list;
        function meTaggableFriends(){
            FB.api(
                "/me/taggable_friends",
                function (response) {
                  if (response && !response.error) {
                    /* handle the result */
                    console.log(response)
    
                        for(var i=0; i<response.data.length; i++){
    
                            var data = response.data;
                            friendsIDarray.push(data[i].id);    
                        }
                        user_friend_list = friendsIDarray.join();
    
                  }
                }
            );
    

    5. Now, we have stored the token ids in user_friend_list for those friends we want to tag in our post and we can use an Open Graph action like this in order to tag friends:

    FB.api(
                          'me/{namespace}:{action}',
                          'post',
                          {
                             {object-type}:'http://example.com/object/', // make sure to have the apropiate og:type meta set
                             place:'https://example.com/place/', // open graph page with metas for location, id for a location page etc
                             tags: user_friend_list, // the tokens ids for those friens you wanna tag and you got on previous step
                             title: 'whatever',
                             message: 'like this, you tag friends @['+ONE_TOKEN_ID_FROM_TAGGABLE_FRIENDS+'] , @['+ONE_TOKEN_ID_FROM_TAGGABLE_FRIENDS+'] etc'
                          }, 
                          function(response) {
                            console.log(response)
                          }
                    );
    

    你可以在上面找到更多相关信息:

    https://developers.facebook.com/docs/opengraph/using-actions/v2.1

    希望你觉得它有用 .

  • 1

    错误消息“您或此应用程序的Open Graph测试用户必须至少发布此操作一次”意味着:在您需要此权限之前,您必须至少调用一次api .

    我之前发生过这种错误 . 当我需要publish_actions权限时,facebook会告诉我:

    enter image description here

    然后我用我的应用程序调用/ me / feed api发布一个feed,然后错误就消失了 .

    如果您是该应用的所有者,开发者或测试用户,则可以在审核批准之前使用这些API . 您可以在仪表板中为应用添加角色 .

相关问题