简体   繁体   中英

js Post on friends facebook wall with taggable_friend ID

first I get all users friends

FB.login(function(response){
        console.log(response);

        FB.api(
            "/me/taggable_friends?fields=name,id,picture.width(100).height(100)",
            function (response) {
                console.log(response);
                if (response && !response.error) {
                    $('#usersList').find('li').remove();
                    response.data.forEach(function(a, b){
                        console.log(a, b);
                        $('#usersList').append('<li class="users__item jsUser" data-fb-name="'+ a.name+'" data-fb-id="'+ a.id+'">'+
                        '<a class="users__link">'+
                        '<img src="'+ a.picture.data.url+'" height="63" width="64" alt="" class="users__pic">'+
                        '</a>'+
                        '</li>');
                    });
                    bindJsUser();
                }
            }
        );



    }, {scope: 'public_profile,user_friends'});

ID of every friend loks like gahdfashjdfg234234137ryuhdsfius43534523wdfwef43r435, and I can't post on wall with that ID

var user = $('#usersList').find('li.active');
    if(!user){
        return;
    }
    // calling the API ...
    var obj = {
        method: 'feed',
        to: user.attr('data-fb-id'), // <-- PROBLEM
        link: 'http://snow.sa-wd.ru',
        picture: 'http://snow.sa-wd.ru/images/preview-greeting.webp',
        name: 'test',
        caption: 'Submit to friend',
        description: 'Using Dialogs for posting to friends timeline.'
    };

    function callback(response) {
        console.log(response['post_id']);
    }

    FB.ui(obj, callback);

error:

API Error Code: 100 API Error Description: Invalid parameter Error Message: AaIIMETTji_8- m19fUI***yc*********GUTQg does not resolve to a valid user ID

The feed dialog is deprecated and should not be used anymore. And the docs say " The ID must be a friend who also uses your app. " - that goes for the "to" parameter. So if you really still want to use the feed dialog, just use /me/friends to get all the friends who authorized your App and use one of the IDs for the "to" parameter.

Btw, you are not allowed to use taggable_friends for anything else than tagging/mentioning. That´s why you only get "tagging tokens", not User IDs.

You would never get it approved for what you want to achieve:

Use of this edge must be reviewed by Facebook before it can be called on behalf of people who use your app.

That being said, it´s bad practice to post on the wall of a friend, even with the deprecated feed dialog. It always looks like spam. That´s why it´s not possible to post to friends who did not authorize your App.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM