4

Imagine the situation when I'm logged in facebook web application as userA. I know userB's nickname but he is not in my friendlist and I do not know his id. And, of course, he does not use my app.

  1. How can I get userB's id via a nickname?
  2. After that how can I get his wall posts?

Are there any specific permissions? May be there are manual pages I've missed?

Valentina
  • 111
  • 1
  • 7

1 Answers1

6

In v1.0, the following was possible:

http://graph.facebook.com/v1.0/{user-name}

However, with v2.0 and v2.1, accessing users via IDs or Usernames not connected to your application is not possible. E.g., trying http://graph.facebook.com/v2.1/{user-name} will throw an error:

{
   "error": {
      "message": "(#803) Cannot query users by their username (user-name)",
      "type": "OAuthException",
      "code": 803
   }
}

Using the new PHP SDK (v4.0.x) you can do the following:

$response = (new FacebookRequest( $session, 'GET', '{user-name}', array(), 'v1.0' ))->execute()->getGraphObject()->asArray();
Niraj Shah
  • 15,087
  • 3
  • 41
  • 60
  • 2
    Unfortunately, if I add version string to my API call, I'm not sure it will still work after [April 30th, 2015](https://developers.facebook.com/docs/apps/changelog). If I try to access user vie its global id I get error message _"The global ID is not allowed. Please use the application specific ID instead."_. How can I get mentioned application specific id for user with global ID ? – Valentina Aug 12 '14 at 09:46
  • Yes, v1.0 calls will stop working after April 30th 2015. You can't get application specific ID unless the user has authorised your app. – Niraj Shah Aug 12 '14 at 09:55
  • Is it possible to call API v1.0 via newest facebook PHP SDK? – Valentina Aug 12 '14 at 17:16
  • Yes, the fifth parameter can be used to specify a version, e.g.: `$response = (new FacebookRequest( $session, 'POST', '/me/feed', $data, 'v1.0' ))->execute()->getGraphObject()->asArray();` – Niraj Shah Aug 14 '14 at 18:38