1
votes

How to post on Facebook with a location(using latitude and longitude) using its JavaScript SDK? Can't find any example to post with a location.

Will Open Graph action creation be required for posting location in the post?

Also, is it possible to share the url of a page and instead make use of Open Graph tags on the page to share the location details for use in Facebook post?

JavaScript code to create post with just text message:

var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response.id);
  }
});

An example in the documentation says:

You can make a POST request to locations edge from the following paths:
/{page_id}/locations

When posting to this edge, a Location will be created.

Does this mean that a location post cannot be created using Graph API for a user's feed?

Reference:

Edited:

Able to find an example to create a post with location attached as answered here:

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

Though the next question is, how to find location id using Latitude and Longitude?

1

1 Answers

0
votes

You can find the location id by https://graph.facebook.com/search?q=karachi&type=page&access_token=YOURTOKEN This will give you the list of places which match karachi.