Facebook Graph API v2.1: getting user id and his posts

…衆ロ難τιáo~ 提交于 2019-12-19 09:02:35

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/25258670/facebook-graph-api-v2-1-getting-user-id-and-his-posts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!