What is a Page ID for the place field in Post Facebook Graph API?

1.7k views Asked by At

I am having trouble while trying to post a message on the current end-user Facebook wall with my Android Application.

So far :

  • The user is logged in with all the required permissions, especially the publish_actions permission ;
  • I am using the last version of Facebook SDK 3.x & Graph API v2 as of May 2014
  • Post to wall works now as of EDIT 2, but there are issues with privacy settings : post cannot be seen by anyone not even the recipient who is tagged in the post ! See EDIT 2 for more details

Here is the documentation for posting a message on the user wall :

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed (go to Publishing)

Regarding the message that needs to be posted on the user' wall, I need to tag some friends that were previously selected by the user. But to use the tag field I need to use the place field. The documentation says :

Name: tags

Comma-separated list of user IDs of people tagged in this post. You cannot specify this field without also specifying a place.

Type: csv[string]


Name: place

Page ID of a location associated with this post.

Type: string

What is location page ID ? How do I get it ?

Oddly enough, in my specefic case, I am offering the possibilty to the user to share is upcoming travel on Facebook.

More oddly enough, this travel is defined by dates and a destination (name of destination + latitude & longitude). The user has the possibility to also share this travel to his friends that are located in his travel's destination hence the need to tag his friends to the wall post.

[EDIT 1]

After looking into @Tobi solutions, I managed to post a message on the end-user wall (in my case me, since I am the developper).

So far : the message is correctly displayed with a friend tagged (a dummy account I use for tests purpouses) and there is also the place : Paris, France.

Using the following search query (thanks @Tobi) search?q=Paris,France&type=place I can get the ID of Paris, France. Since I did not code the part to retrieve the Place ID it put it manually in the code for the sake of testing the feature first.

[END OF EDIT 1]

[EDIT 2]

I noticed I forgot to add the part with the privacy values to my args Bundle. But it did not change a damn thing : my post is only visible to me alone.

Going to my Facebook wall, here is what I get :

Hovering the public parameters of the posts (a padlock icon) says "All tagged persons". Clicking on the icon shows the list of settings with only "Only me" selected.

Why "only me" even though I specifically said me + my dummy account in the request parameters ?

Even weirder : changing the property of the publication parameters to "customized" with my dummy account does not change a damn thing as well. Just why ? Facebook is really getting on my nerve...

For the rest, the message content is correctly displayed and the related place is the good one. At least a got that correctly. But still, I just don't get the rest ...

[END OF EDIT 2]

So here is the updated code :

if (this.session != null && this.session.isOpened()) {
    final Bundle args = new Bundle();
    if (this.selectedContacts.isEmpty() == false) { 
        args.putString("message", message);
        args.putString("place", "170558129707208"); //manually added Paris, France ID
        String tags = "";
//here I made some modifications regarding the tags so that is built correctly
         for (int it = 0; it < this.selectedContacts.size(); it++) {
            final String name = this.selectedContacts.get(it).toString();
            final String friendID = String.valueOf(getIdFromName(name)); // returns an int
            if (it == this.selectedContacts.size())
                tags += friendID;
            else
            tags += friendID + ",";
        }

// Forgot to add privacy values to bundle !
        final JSONObject privacyValues = new JSONObject(); //not android JSON, but JSON-Simple lib
        privacyValues.put("value", "CUSTOM");
        String allow = this.currentUser.getId() + "," + tags;
        privacyValues.put("allow", allow); // to limit the visibility of this post
        args.putString("privacy", privacyValues.toJSONString()); //forgot that one...
        final Request shareTravelRequest = new Request(this.session, this.currentUser.getID() + "/feed",
                args, HttpMethod.POST, new Request.Callback() {
                public final void onCompleted(final Response response) {
                    //TODO    
                }
            }
        );
        final Response response = shareTravelRequest.executeAndWait();
        if (response.getError() == null) // in this case, no error occurred
            return true;
        else {
            this.lastErrorMessage = response.getError().getErrorMessage();
            Log.e("Something went wrong while posting Facebook message", this.lastErrorMessage);
            Log.e("Error type is", response.getError().getErrorType());
            Log.e("Error code is", String.valueOf(response.getError().getErrorCode()));
            return false;
        }
    }
}

Unfortunately I must have mistaken somewhere because although the post does appear on my Facebook wall with my dummy account tagged and with the correct link to the place, my dummy account cannot see the post.

I tried creating manually the same post on my Facebook wall by using the following settings :

  1. First I supplied a message
  2. Second I supplied a place
  3. Third I tagged my dummy account
  4. Four I choose who can see this post : me and my dummy account
  5. And finally, I post the message.

In this case, my dummy account sees the post both on its wall and on my wall.

So I would like to know what parameters I must get wrong because there is not much parameters and I just don't see why.

Thanks !

2

There are 2 answers

3
Tobi On

You can either use the Search and use the type place (https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0#search), or, if you have positioning date, use an FQL query on the place table (https://developers.facebook.com/docs/reference/fql/place/) as described here: Facebook places: order results by distance

0
phwd On

Use two test accounts made via Facebook Developer App settings and not a dummy account that breaks TOS. Since you request publish_actions you probably didn't submit the app for review. Unless your dummy account is a developer/tester in roles as well (which is breaking the TOS again) then your dummy account will not be able to see the post.

Only developers and testers of an unpublished application can see posts made by that application.