Facebook Graph API v2.1:获取用户ID和他的帖子 [英] Facebook Graph API v2.1: getting user id and his posts

查看:107
本文介绍了Facebook Graph API v2.1:获取用户ID和他的帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下当我以userA身份登录Facebook网页应用程式时,情况如此。我知道userB的昵称,但他不在我的朋友列表,我不知道他的身份。而且,他当然不使用我的应用程序。


  1. 如何通过昵称获取userB的id?

  2. 之后如何获得他的墙上信息?

有没有特定权限?可能有我错过的手册页?

解决方案

在v1.0中,以下是可能的:



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



但是,使用v2.0和v2.1,无法通过未连接到应用程序的ID或用户名访问用户。例如,尝试 http://graph.facebook.com/v2.1/ {user-name} 会抛出错误:

  {
error:{
message:(#803)用用户名(user-name)无法查询用户
type:OAuthException,
code:803
}
}

使用新的PHP SDK(v4.0.x),您可以执行以下操作:

  $ response =(new FacebookRequest($ session,'GET','{user-name}',array(),'v1.0')) - > execute() - > getGraphObject() asArray(); 


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?

解决方案

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

这篇关于Facebook Graph API v2.1:获取用户ID和他的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆