Facebook Graph API GET 请求 - 应包含“字段";参数(Swift,Facebook SDK v4.5.1) [英] Facebook Graph API GET request - Should contain "fields" parameter (Swift, Facebook SDK v4.5.1)

查看:19
本文介绍了Facebook Graph API GET 请求 - 应包含“字段";参数(Swift,Facebook SDK v4.5.1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 iOS 应用在注册期间使用 Facebook 的 Graph API 请求来获取用户信息,这在升级到 Facebook 的最新 SDK 之前运行良好.升级后,我收到一个运行时错误,指出:FBSDKLog:从 Graph API v2.4 开始,/me 的 GET 请求应包含显式的字段"参数.

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".

代码如下:

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 = "https://graph.facebook.com/(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)")
                }
            })
        }
    })
}

错误信息在行:

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

在升级到 Facebook 的 SDK v4.5.1 之前,此代码运行良好,但我不知道现在要更改什么才能使其正常工作.非常感谢任何可以帮助我的人!

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!

推荐答案

这一行需要一个非 nil 的参数值

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:

所以对于 ObjC 来说就是这样,例如,所以上面的内容如下:

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

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

很快就会有类似的东西

像这样:

parameters:["fields": "email"]

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

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

我添加此更新是为了向人们展示您在何处找到上述字段的参数,这是一个快速链接:

https://developers.facebook.com/docs/graph-api/reference/user

以下信息的格式如下,有点,我只是很快做到了:

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

参数" 类型"

说明"

id 数字字符串

此人的用户帐户的 ID.此 ID 对每个应用程序都是唯一的并且不能跨不同的应用程序使用.我们的升级指南提供有关特定于应用的 ID 的更多信息

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

关于字符串

此人个人资料的关于我"部分

The About Me section of this person's profile

age_range 年龄范围

此人的年龄段表示为最小值和最大值年龄.比如大于18,小于21.

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

生物 字符串

个人简介

生日字符串

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

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)

上下文 用户上下文

此人的社会背景

货币 货币

此人的当地货币信息

设备列表

此人正在使用的设备列表.这将只返回 iOS 和安卓设备

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

教育列表

受教育程度

电子邮件字符串

此人的主要电子邮件地址列在其个人资料中.这个领域如果没有可用的有效电子邮件地址,则不会返回

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 列表

喜欢的运动员

favorite_teams 列表

喜欢的球队

first_name 字符串

此人的名字

性别字符串

此人选择的性别,男性或女性.这个值将是如果性别设置为自定义值,则省略

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

家乡页面

人的家乡

inspirational_people名单

这个人的励志人

install_type 枚举

安装类型

已安装 bool

是否安装了发出请求的应用?

Is the app making the request installed?

interested_in 列表

此人感兴趣的性别

is_shared_login bool

这是共享登录吗(例如灰色用户)

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

is_verified bool

拥有大量粉丝的人可以拥有他们的身份由 Facebook 手动验证.该字段表示是否通过这种方式验证此人的个人资料.这是与众不同的来自验证字段

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

语言列表

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

Facebook Pages representing the languages this person knows

姓氏 字符串

此人的姓氏

链接字符串

指向此人时间线的链接

位置页面

此人在其个人资料中输入的当前位置.此字段与签到无关

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

locale 字符串

人的语言环境

meeting_for 列表

这个人有兴趣见面

**middle_name 字符串

**middle_name string

此人的中间名

名称 字符串

此人的全名

核心默认

name_format 字符串

人名格式正确处理中文、日文或韩国订购

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

payment_pricepoints 付款价格点

此人的付款价格点

test_group 无符号 int32

test_group unsigned int32

平台测试组

政治字符串

此人的政治观点

relationship_status 字符串

此人的关系状态

宗教字符串

该人的宗教信仰

security_settings 安全设置

安全设置

重要的_其他用户

此人的另一半

体育列表

这个人喜欢的运动

引号字符串

这个人最喜欢的名言

third_party_id 字符串

包含匿名但唯一标识符的字符串人.您可以将此标识符用于第三方

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

时区浮动(最小:-24)(最大:24)

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

此人当前时区与 UTC 的偏移

The person's current timezone offset from UTC

token_for_business 字符串

在企业的应用中相同的令牌.访问这个令牌要求此人登录到您的应用程序.这个令牌如果拥有该应用的企业发生变化,将会发生变化

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 日期时间

更新时间

shared_login_upgrade_required_by 日期时间

共享登录需要升级到商务管理器的时间通过

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

已验证 bool

表示账户是否已经过验证.这不同于is_verified 字段.如果有人采取任何措施,则被视为经过验证以下操作之一:

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 VideoUploadLimits

视频上传限制

viewer_can_send_gift bool

观众可以给这个人送礼物吗?

Can the viewer send a gift to this person?

网站字符串

此人的网站

工作列表

个人工作经历的详细信息

Details of a person`s work experience

public_key 字符串

此人的 PGP 公钥

封面 封面照片

<小时>

此外,这是当前的边缘"内容:边缘"内容的格式大致是这样的,我很快就做到了:

边缘"

说明"

favorite_requests

开发者最喜欢的 Graph API 请求

Developers' favorite requests to the Graph API

请求历史

开发者图形 API 请求历史

Developers' Graph API request history

帐户

此人管理/作为其管理员的 Facebook 主页

Facebook Pages this person administers/is an admin for

成就

在 Facebook 游戏中取得的成就

Achievements made in Facebook games

帐户

此人有权访问的广告帐户

The advertising accounts to which this person has access

帐户组

广告帐户组

广告合同

此人的广告合同

admined_groups

将用户管理员分组

广告网络分析

此人的 Audience Network 应用的洞察数据

Insights data for the person's Audience Network apps

专辑

此人创建的相册

应用请求

此人来自应用的待处理请求

This person's pending requests from an app

apprequestformerrecipients

应用请求

书籍

此人的个人资料中列出的书籍

The books listed on this person's profile

用户管理的域

活动

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

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

家庭

此人的家庭关系.

stream_filters

可应用于 News Feed 边缘的过滤器列表

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

好友列表

此人的自定义好友列表

ids_for_business

企业实体可以使用业务经理.此边返回此用户拥有的 ID 列表在任何其他应用中

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

可以邀请安装 Facebook Canvas 应用的朋友列表

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

游戏

这个人喜欢的游戏

群组

此人所属的 Facebook 群组

The Facebook Groups that the person belongs to

喜欢

此人喜欢的所有主页

电影

这个人喜欢的电影

音乐

这个人喜欢的音乐

对象

对象

权限

此人授予此应用的权限

照片

此人被标记或上传的照片

Photos the person is tagged in or has uploaded

图片

此人的头像

tagged_places

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

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

promotable_domains

用户可以推广的所有域

promotable_events

用户可以推广的所有活动.

All the events which user can promote.

taggable_friends

可以在通过图谱 API 发布的内容中标记的朋友

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

电视

这个人喜欢的电视节目

视频

此人被标记或上传的视频

Videos the person is tagged in or uploaded

video_broadcasts

此人的视频广播

应用程序

此人开发的 Facebook 应用.

The Facebook apps that this person is a developer of.

签到

此人进行的签到.

饲料

发布的帖子(包括状态更新)和链接的提要这个人.

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

好友请求

某人待处理的好友请求.

A person's pending friend requests.

朋友

一个人的朋友.

一个人的 Facebook 主页提要.

A person's Facebook homepage feed.

收件箱

一个人的 Facebook 消息收件箱.

A person's Facebook Messages inbox.

位置

包含位置信息和此人已被标记.这对于构建一个此人去过的地方的年表.

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.

共同好友

两人共同好友列表.

通知

一个人收到的未读 Facebook 通知.

The unread Facebook notifications that a person has.

发件箱

一个人的 Facebook 消息发件箱.

A person's Facebook Messages outbox.

问题

一个人提出的问题.

分数

此人从 Facebook Games 获得的分数播放.

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

订阅者

关注此人的个人资料.

订阅

此人关注的个人资料.

这篇关于Facebook Graph API GET 请求 - 应包含“字段";参数(Swift,Facebook SDK v4.5.1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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