简体   繁体   中英

How to post to Facebook with location attached using JavaScript SDK

I am trying to post to a user's Facebook wall using Javascript SDK from a Phonegap mobile app. I am able to post a message to the user's wall from my app. I want to attach a location to the post so that it looks like a checkin. Facebook checkin was working fine, but since it was deprecated, I want to use Post as suggested by Facebook.

Below is my code:

    FB.api('/me/feed', 'post', {
        name: 'SomeName',
        message: 'SomeMessage',
        place: {
               'id': pageId,
               'name': name,
               'location': {
                           'latitude': latitude,
                           'longitude': longitude
                    }
               }
    },
    function (response) {
    if(response){
        alert("Post was published!");
    }
    else {
        alert("Post was not published. Try again.")
    }
    }); 

The place tag needs the id, name and location with the latitude and longitude, so I provided them as above. I get the alert message saying the Post was published!, but it isn't posted to the user's wall. If I take out the place field, it works fine.

Thanks in advance.

Set place only for location ID. This example just worked as I searched solution for my application:

FB.api('/me/feed', 'post', {
    name: 'SomeName',
    message: 'SomeMessage',
    place: '106039436102339' // ID for Tallinn, Estonia
}, function (response) {}); 

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