Facebook Graph API GET请求

编程入门 行业动态 更新时间:2024-10-27 22:34:10
本文介绍了Facebook Graph API GET请求 - 应包含“fields”参数(Swift,Facebook SDK v4.5.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的iOS应用程序在注册时使用Facebook的Graph API请求来获取用户信息,在升级到Facebook的最新SDK之前,该操作可以正常运行。升级后,我收到运行时错误,指出:FBSDKLog:从Graph API v2.4开始,GET请求/我应该包含一个明确的fields参数。

这是代码:

func requestFacebook(){ let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath:me,参数:nil) graphRequest.startWithCompletionHandler({(connection,result,error))> Void in if((error)!= nil) { //进程错误 println(错误:\(错误))} 如果错误== nil {让生日:NSString =(result.valueForKey(birthday)as?NSString)! var currentDate = NSDate() var birthdayFormatter = NSDateFormatter() let userCalendar = NSCalendar.currentCalendar() birthdayFormatter.dateFormat =MM / DD / YYYY var birthdayNSDate = birthdayFormatter.dateFromString(生日为String) var userAge = self.calculateAge(birthdayNSDate!) PFUser.currentUser()![age] = userAge var facebookID:NSString =(result.valueForKey(id)as? NSString的)! var pictureURL =graph.facebook/\(facebookID)/picture?type=large&return_ssl_resources=1 var URLRequest = NSURL(string:pictureURL ) var URLRequestNeeded = NSURLRequest(URL:URLRequest!) NSURLConnection.sendAsynchronousRequest(URLRequestNeeded,queue:NSOperationQueue.mainQueue(),completionHandler:{(response:NSURLResponse!,data:NSData! ,错误:NSError!) - > 如果错误== Nil { var picture = PFFile(data:data) PFUser.currentUser()![picture] =图片 PFUser.currentUser()!。saveInBackgroundWithBlock({(success,error) - > Void in 如果错误== nil { var userPicture:PFFile = PFUser。 currentUser()!. valueForKey(picture)as!PFFile userPicture.getDataInBackgroundWithBlock {(imageData,错误) - > 如果错误== Nil { self.meProfileImageView.image = UIImage(data:imageData!) var userName:String = PFUser.currentUser()!. valueForKey (用户名)为! String var userAge:Int = PFUser.currentUser()!. valueForKey(age)as! Int self.meLabel.text =\(userName),\(userAge) self.findFriends() } } } else { println(error)} })} else { println(Error :\(error.localizedDescription))} })} })} pre>

错误信息位于以下行:

让生日:NSString =(result.valueForKey(birthday)as?NSString)!

此代码在升级到Facebook的SDK v4.5.1之前运行得很好,但我不知道改变,使这项工作现在。非常感谢任何可以帮助我的人!

解决方案

此行需要一个不为零的参数值

let graphRequest:FBSDKGraphRequest = FBSDKGraphRequest(graphPath:me,参数:nil)

我将扩展更多,例如,这是psuedo代码:

所以对于ObjC它例如,这样,所以上面的内容将读取以下内容:

参数:@ {@fields:@ id,name}

在快速这将是类似的东西

如下所示:

参数:[fields:email]

这只是两个字段,再次是伪代码,但您需要指定参数

更新:

此更新显示在哪里找到字段的参数如上所述,这里是一个快速链接:

这是Paramters字段信息(这应该保持与FBSDK大致静态,其中一些是核心,意味着它不会真的改变那么多,但是我会随时更新):

developers.facebook/docs/graph-api/reference/user

以下信息的格式如下,我刚刚做到这一点:

参数 类型 / strong>

描述

id 数字字符串

此人的用户帐户的ID。此ID是每个应用程序唯一的,不能在不同的应用程序中使用。我们的升级指南提供关于应用程序特定ID的更多信息

关于字符串

这个人的个人资料的关于我部分

age_range AgeRange

这个人的年龄段表示为最低和最高年龄。例如,超过18岁,少于21岁。

生物字符串

该人的生物

生日字符串

该人的生日。这是一个固定的格式字符串,如MM / DD / YYYY。 然而,人们可以控制谁能看到他们出生的年份与月份和日期分开,所以这个字符串只能是年(YYYY)或月+日(MM / DD)

上下文 UserContext

此人的社交环境

货币货币

该人的当地货币信息

设备列表

该人正在使用的设备列表。这将只返回iOS和 Android设备

教育列表

该人的教育

电子邮件字符串

该人的主要电子邮件地址列在他们的资料。如果没有有效的电子邮件地址,则不会返回此字段

收藏夹运行列表

运动员喜欢

favorite_teams 列表

运动

first_name 字符串

该人的名字

性别字符串

此人,男性或女性选择的性别。如果将性别设置为自定义值,则此值将为。

hometown 页面

该人的家乡

inspirational_people 列表

人的灵感人物

install_type 枚举

安装类型

安装 bool

是否安装了请求的应用程序?

interested_in 列表

性感个人感兴趣

is_shared_login bool

这是一个共享登录名(例如灰色用户)

is_verified bool

拥有大量关注者的人们可以通过Facebook手动验证其身份的真实性。该字段指示该人的个人资料是否以此方式进行验证。这是来自已验证字段的

语言列表

Facebook页面代表此人所知的语言

last_name 字符串

链接字符串

指向该人的时间轴的链接

位置页面

该人在他们的个人资料中输入的当前位置。 此字段与签入无关

区域设置字符串

该人的地区

meeting_for 列表

**中间名字符串

该人的中间名称

名称字符串

该人的全名

CoreDefault

name_format 字符串

该人的名称格式正确地处理中文,日文或韩国订购

payment_pricepoints PaymentPricepoints

该人的付款点/ p>

test_group unsigned int32

平台测试组

政治字符串

该人的政治观点

relationship_status 字符串

该人的关系状态

宗教字符串

该人的宗教信仰

security_settings SecuritySettings

安全设置

important_other 用户

该人的重要其他

/ strong>列表

运动这个人喜欢

引号 string

该人最喜欢的报价

third_party_id 字符串

一个包含人的匿名但唯一标识符的字符串。您可以使用此标识符与第三方

时区 float(最小:-24)(最大:24)

该人目前的时区偏离UTC

token_for_business 字符串

企业应用程式中的令牌相同。访问此令牌需要该人登录到您的应用程序。

updated_time datetime

更新时间

shared_login_upgrade_required_by datetime

共享时间

验证 bool

表示帐户是否已验证。这是不同于的is_verified字段。有人被认为是否有任何的以下操作:

注册手机确认他们通过短信帐户输入有效的信用卡

video_upload_limits VideoUploadLimits

视频上传限制

viewer_can_send_gift bool

观众可以向此人发送礼物吗?

网站字符串

该人的网站

工作列表

一个人的工作经验

public_key 字符串

该人的PGP公钥

封面 CoverPhoto

另外,这里是当前的边缘的东西:边缘的格式是这个,大概是我这样做很快:

边缘

说明

favorite_requests

Graph API最喜欢的请求

request_history

开发人员的图形API请求历史

帐户

此人管理的Facebook页面/是管理员

成就

Facebook游戏中取得的成就

adaccounts

此人有权访问的广告帐户

adaccountgroups

广告帐户组

/ strong>

该人的广告合同

admined_groups

为用户管理员分组

adnetworkanalytics

个人观众网络应用的数据分析

相册

此人创建的相册

apprequests

这个人的应用程序的待处理请求

apprequestformerrecipients

应用程序请求

图书

本人个人资料中列出的图书

用户管理员的域名

事件

此人的活动。默认情况下,这不包括人已拒绝或未回复到

家庭

的事件

这个人的家庭关系。

stream_filters

可应用于新闻Feed边缘的筛选器列表

friendlists

该人的自定义朋友列表

ids_for_business

业务实体可以声明拥有权多个应用程序使用业务经理。此边缘返回此用户在任何其他应用程序中具有的ID列表。

invitable_friends

可邀请您安装Facebook Canvas应用程序的朋友列表

游戏

这个人喜欢的游戏

该人所属的Facebook群组

喜欢

全部这个人喜欢的页面

电影

这个人喜欢的电影

音乐

音乐此人喜欢

对象

对象

strong>

该人已授予此应用的权限

pho

该人被标记或已上传的照片

图片

strong>

该人的个人资料图片

tagged_places

此人标记的地点列表。它可以包括视频上的标签,帖子,状态或链接

可推出的域

用户可以宣传的所有域名

可推出的事件

用户可以宣传的活动。

taggable_friends

可以标记的朋友通过Graph API发布的内容

电视

电视显示此人喜欢

视频

该人被标记或上传的视频

video_broadcasts

此人的视频广播

应用程序

此人是开发人员的Facebook应用程序。

签入

饲料

帖子的Feed(包括状态更新)和由发布的链接此人。

friendrequests

一个人的待处理的朋友请求。

朋友

一个人的朋友。 p>

首页

一个人的Facebook主页Feed。

收件箱

一个人的Facebook消息收件箱。

位置

包含位置信息的帖子和照片的Feed,以及此人被标记的。这对于构建人们访问过的地点的年表是有用的。

共同交友

两人之间的共同朋友名单。

通知

某人所未知的Facebook通知。

发件箱

一个人的Facebook消息发件箱。

问题

一个人的问题已经创建了。

分数

他们已经玩。

订阅者

个人资料

subscribedto

此人的个人资料以下。

My iOS app uses Facebook's Graph API Request during sign up to get user information, which worked fine prior to upgrading to Facebook's newest SDK. After upgrading, I'm getting a runtime error stating: "FBSDKLog: starting with Graph API v2.4, GET requests for /me should contain an explicit "fields" parameter".

Here is the code:

func requestFacebook() { let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil) graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in if ((error) != nil) { // Process error println("Error: \(error)") } else if error == nil { let birthday : NSString = (result.valueForKey("birthday") as? NSString)! var currentDate = NSDate() var birthdayFormatter = NSDateFormatter() let userCalendar = NSCalendar.currentCalendar() birthdayFormatter.dateFormat = "MM/DD/YYYY" var birthdayNSDate = birthdayFormatter.dateFromString(birthday as String) var userAge = self.calculateAge(birthdayNSDate!) PFUser.currentUser()!["age"] = userAge var facebookID: NSString = (result.valueForKey("id") as? NSString)! var pictureURL = "graph.facebook/\(facebookID)/picture?type=large&return_ssl_resources=1" var URLRequest = NSURL(string: pictureURL) var URLRequestNeeded = NSURLRequest(URL: URLRequest!) NSURLConnection.sendAsynchronousRequest(URLRequestNeeded, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!, error: NSError!) -> Void in if error == nil { var picture = PFFile(data: data) PFUser.currentUser()!["picture"] = picture PFUser.currentUser()!.saveInBackgroundWithBlock({ (success, error) -> Void in if error == nil { var userPicture:PFFile = PFUser.currentUser()!.valueForKey("picture") as! PFFile userPicture.getDataInBackgroundWithBlock { (imageData, error) -> Void in if error == nil { self.meProfileImageView.image = UIImage(data: imageData!) var userName:String = PFUser.currentUser()!.valueForKey("username") as! String var userAge:Int = PFUser.currentUser()!.valueForKey("age") as! Int self.meLabel.text = "\(userName), \(userAge)" self.findFriends() } } } else { println(error) } }) } else { println("Error: \(error.localizedDescription)") } }) } }) }

The error message is at the line:

let birthday : NSString = (result.valueForKey("birthday") as? NSString)!

This code ran perfectly fine before upgrading to Facebook's SDK v4.5.1, but I don't know what to change to make this work now. Huge thanks to anyone that can help me!

解决方案

this line needs a parameters value that is NOT nil

let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)

I'll expand more, for example, and this is psuedo code of sorts:

so for ObjC it would be this, for example, so the the above would read the following:

parameters:@{@"fields": @"id, name"}

In swift it would be something similar

something like this:

parameters:["fields": "email"]

This is for just two fields, and again it's psuedo code, but you need to specify the parameters

UPDATE:

Im adding this update to show folks where you find the parameters for the fields as described above, here's a quick link:

Here's the Paramters field info (this should stay roughly static with FBSDK, some of this is "core" which means it won't really change that much, but I'll update whenever I can):

developers.facebook/docs/graph-api/reference/user

The format of the info below is the following, sort of, I just did this quickly:

"parameter" "type"

"description"

id numeric string

The id of this person's user account. This ID is unique to each app and cannot be used across different apps. Our upgrade guide provides more information about app-specific IDs

about string

The About Me section of this person's profile

age_range AgeRange

The age segment for this person expressed as a minimum and maximum age. For example, more than 18, less than 21.

bio string

The person's bio

birthday string

The person's birthday. This is a fixed format string, like MM/DD/YYYY. However, people can control who can see the year they were born separately from the month and day so this string can be only the year (YYYY) or the month + day (MM/DD)

context UserContext

Social context for this person

currency Currency

The person's local currency information

devices list

The list of devices the person is using. This will return only iOS and Android devices

education list

The person's education

email string

The person's primary email address listed on their profile. This field will not be returned if no valid email address is available

favorite_athletes list

Athletes the person likes

favorite_teams list

Sports teams the person likes

first_name string

The person's first name

gender string

The gender selected by this person, male or female. This value will be omitted if the gender is set to a custom value

hometown Page

The person's hometown

inspirational_people list

The person's inspirational people

install_type enum

Install type

installed bool

Is the app making the request installed?

interested_in list

Genders the person is interested in

is_shared_login bool

Is this a shared login (e.g. a gray user)

is_verified bool

People with large numbers of followers can have the authenticity of their identity manually verified by Facebook. This field indicates whether the person's profile is verified in this way. This is distinct from the verified field

languages list

Facebook Pages representing the languages this person knows

last_name string

The person's last name

link string

A link to the person's Timeline

location Page

The person's current location as entered by them on their profile. This field is not related to check-ins

locale string

The person's locale

meeting_for list

What the person is interested in meeting for

**middle_name string

The person's middle name

name string

The person's full name

CoreDefault

name_format string

The person's name formatted to correctly handle Chinese, Japanese, or Korean ordering

payment_pricepoints PaymentPricepoints

The person's payment pricepoints

test_group unsigned int32

Platform test group

political string

The person's political views

relationship_status string

The person's relationship status

religion string

The person's religion

security_settings SecuritySettings

Security settings

significant_other User

The person's significant other

sports list

Sports this person likes

quotes string

The person's favorite quotes

third_party_id string

A string containing an anonymous, but unique identifier for the person. You can use this identifier with third parties

timezone float (min: -24) (max: 24)

The person's current timezone offset from UTC

token_for_business string

A token that is the same across a business's apps. Access to this token requires that the person be logged into your app. This token will change if the business owning the app changes

updated_time datetime

Updated time

shared_login_upgrade_required_by datetime

The time that the shared loginneeds to be upgraded to Business Manager by

verified bool

Indicates whether the account has been verified. This is distinct from the is_verified field. Someone is considered verified if they take any of the following actions:

Register for mobile Confirm their account via SMS Enter a valid credit card

video_upload_limits VideoUploadLimits

Video upload limits

viewer_can_send_gift bool

Can the viewer send a gift to this person?

website string

The person's website

work list

Details of a person`s work experience

public_key string

The person's PGP public key

cover CoverPhoto

Also, here's the current "Edge" stuff: The format for "Edge' stuff is this, roughly, I did this quickly:

"Edge"

"Description"

favorite_requests

Developers' favorite requests to the Graph API

request_history

Developers' Graph API request history

accounts

Facebook Pages this person administers/is an admin for

achievements

Achievements made in Facebook games

adaccounts

The advertising accounts to which this person has access

adaccountgroups

Ad account groups

adcontracts

The person's ad contracts

admined_groups

Groups the user admins

adnetworkanalytics

Insights data for the person's Audience Network apps

albums

The photo albums this person has created

apprequests

This person's pending requests from an app

apprequestformerrecipients

App requests

books

The books listed on this person's profile

domains

The domains the user admins

events

Events for this person. By default this does not include events the person has declined or not replied to

family

This person's family relationships.

stream_filters

A list of filters that can be applied to the News Feed edge

friendlists

The person's custom friend lists

ids_for_business

Business entities can claim ownership of multiple apps using the Business Manager. This edge returns the list of IDs that this user has in any of those other apps

invitable_friends

A list of friends that can be invited to install a Facebook Canvas app

games

Games this person likes

groups

The Facebook Groups that the person belongs to

likes

All the Pages this person has liked

movies

Movies this person likes

music

Music this person likes

objects

Objects

permissions

The permissions that the person has granted this app

photos

Photos the person is tagged in or has uploaded

picture

The person's profile picture

tagged_places

List of tagged places for this person. It can include tags on videos, posts, statuses or links

promotable_domains

All the domains user can promote

promotable_events

All the events which user can promote.

taggable_friends

Friends that can be tagged in content published via the Graph API

television

TV shows this person likes

videos

Videos the person is tagged in or uploaded

video_broadcasts

Video broadcasts from this person

applications

The Facebook apps that this person is a developer of.

checkins

The checkins this person has made.

feed

The feed of posts (including status updates) and links published by this person.

friendrequests

A person's pending friend requests.

friends

A person's friends.

home

A person's Facebook homepage feed.

inbox

A person's Facebook Messages inbox.

locations

A feed of posts and photos that include location information and in which this person has been tagged. This is useful for constructing a chronology of places that the person has visited.

mutualfriends

The list of mutual friends between two people.

notifications

The unread Facebook notifications that a person has.

outbox

A person's Facebook Messages outbox.

questions

The questions that a person has created.

scores

The scores this person has received from Facebook Games that they've played.

subscribers

The profiles that are following this person.

subscribedto

The profile that this person is following.

更多推荐

Facebook Graph API GET请求

本文发布于:2023-11-16 16:53:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606117.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Facebook   Graph   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!