Facebook Graph API GET API - must contain the "fields" parameter (Swift, Facebook SDK v4.5.1)

My iOS app uses the Facebook Graph API during signup to get user information that worked great before moving to the new Facebook SDK. After updating, I get a runtime error: "FBSDKLog: starting with Graph API v2.4, the GET requests for / me should contain an explicit parameter for the" field ".

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 = "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)") } }) } }) } 

The error message is on the line:

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

This code worked fine before moving to the Facebook SDK v4.5.1, but I don’t know what to change to make this work now. Many thanks to everyone who can help me!

+53
ios facebook xcode swift facebook-graph-api
Aug 16 '15 at 3:58
source share
5 answers

this string requires a parameter value that is not nil

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

I will expand more, for example, and this is the psuedo code:

so for ObjC, this would be, for example, so that the above reads the following:

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

In quick it would be something similar

something like that:

 parameters:["fields": "email"] 

This is only for two fields, and again this is psuedo code, but you need to specify the parameters




UPDATE:

I am adding this update to show people where you will find options for fields, as described above, here's a quick link:

Here is information about Parameters parameters (this should remain approximately static with FBSDK, some of them are the "core", which means that it will not change so much, but I will update it every time I can):

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

The format of the information below is as follows: I just did it quickly:

"parameter " type

"Description"

id numeric string

The user ID of this user. This identifier is unique for each application. and can not be used in different applications. See our update guide for more information on application identifiers.

about line

About section of this user 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

Bio man

birthday string

Man’s birthday. This is a fixed format string, such as MM / DD / YYYY. However, people can control who can see the year in which they were born separately from the month and day, so this line can only be a year (YYYY) or a month + day (MM / DD)

UserContext context

Social context for this person

Currency Currency

Local Currency Information

device list

A list of devices that a person uses. This will only return iOS and Android devices.

educational list

Training people

email string

The primary email address of the person listed on their profile. This field will not be returned if a valid email address is not available.

list of favorite_files

Athletes Who Like People

list of favorite_files

Sports teams that like people

first_name string

Name of man

gender string

Gender chosen by this person, man or woman. This value will be omitted if the gender is set to a custom value.

hometown Page

Man, hometown

inspirational_people list

Man inspiring people

install_type enum

type of instalation

installed bool

Is the application installing the request installed?

interesting_in list

Gives a person interest in

is_shared_login bool

This is a common login (e.g. gray user)

is_verified bool

People with a large number of followers can have their identity authenticated manually verified by Facebook. This field indicates whether the person’s profile is verified in this way. This is from a validated field.

Languages List

Facebook pages representing languages ​​that this person knows

last_name string

Surname

link string

Human Link Timeline

Location Page

The current location of the user entered by them in their profile. This field is not associated with registration

locale string

Face locale

meeting_for list

What a person is interested in meeting for

** middle_name string

Middle name of person

name string

Person's full name

Coredefault

format_name string

The name of the person formatted for the correct processing of a Chinese, Japanese, or Korean order

payment_pricepoints Payment Destinations

Exact person payment prices

test_group unsigned int32

Platform control group

political line

Personal political views

link_status string

Human Relationship Status

religion string

Human religion

security_settings SecuritySettings

Security Settings

significant_other User

Man significant other

sports list

Sports this man loves

quotes string

Personal favorite quotes

third_party_id string

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

time zone float (min: -24) (max: 24)

User UTC Canceled Time Zone

token_for_business string

A token that is the same in business applications. Access to this token requires a person to register in your application. This token will change if the business owning the application changes

updated_time datetime

Update time

shared_login_upgrade_required_by datetime

The time during which general logon must be updated to Business Manager by

checked by bool

Indicates whether the account has been verified. This is different 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 present to this person?

website

User website

job list

Information about the experience of a person

public_key string

PGP public key

CoverPhoto cover




In addition, here is the current "Edge" material: the format for the "Edge" material is, roughly speaking, I did it quickly:

"Edge"

"Description"

favorite_requests

Favorite Developer API Chart Requests

request_history

Developer Charting API Query History

accounts

The Facebook pages this person controls / is an administrator for

Achievements

Achievements made in games on Facebook

adaccounts

Advertising accounts that this person has access to

adaccountgroups

Ad Account Groups

adcontracts

Custom Ads Contracts

admined_groups

Groups user administrators

adnetworkanalytics

Event data for the user of the App for the audience network

albums

Photo albums created by this person

apprequests

This user is waiting for requests from the application.

apprequestformerrecipients

Application Requests

the books

Books listed in this person profile

domains

Domains that the user supports

developments

Events for this person. By default, this does not include events the person refused or did not respond to

a family

This is a family relationship.

stream_filters

List of filters that can be applied to the edge of the feed.

friendlists

Custom User Friends List

ids_for_business

Business entities may require ownership of several applications using the Business Manager. This edge returns a list of identifiers that this user has in any of these applications.

invitable_friends

List of friends who may be asked to install the Facebook Canvas app

games

Games that like this person

groups

Facebook groups to which the person belongs

like

All pages that this person liked

films

This person likes movies

music

The music this man loves

objects

The objects

permissions

Rights granted by this person for this application.

photos

Photos man tagged or uploaded

picture

Face Profile Image

tagged_places

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

promotable_domains

All domain users can promote

promotable_events

All events that the user can promote.

taggable_friends

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

the television

TV shows that this person loves

video

Video tagged or uploaded

video_broadcasts

Transferring videos from this person

applications

Facebook applications that this person is a developer.

inspections

Records of this person are made.

feed

Submission of messages (including status updates) and links published by this person.

friendrequests

Request pending friends.

friends

Friends of friends.

home

Facebook personal site.

Inbox

Inbox for Facebook person.

location

Submitting messages and photos containing location information and to which this person has been tagged. This is useful for building a chronology of the places a person has visited.

mutual friends

List of mutual friends between two people.

notifications

Unread Facebook notifications of what a person has.

outgoing

Private messages for Facebook people.

the questions

The questions that man has created.

assessments

Ratings received by this person from the games on Facebook that they have played.

subscribers

Profiles following this person.

subscribed to

The profile that this person follows.

+118
Aug 16 '15 at 4:42 on
source share
— -

use "fields" as a key and then commas separate your values

 let params = ["fields": "email, friends"] 
+23
Aug 17 '15 at 17:29
source share

In Obj-C, insert the logInWithReadPermissions method:

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

If you leave zero in the parameters, you will only get the identifier and name in the result object, although you have set, for example:

 NSArray *permissionsArray = @[ @"email", @"public_profile"]; 

The documentation is not very clear, hope this can help.

+12
Oct 07 '15 at 13:41
source share

I had the same problem, but adding field parameters would create a query error when retrieving the user's photo. I solved this problem by adding a simple parameters:@{@"fields": @""} code to the code:

 FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:[NSString stringWithFormat:@"me/picture"] parameters:@{@"fields": @""} HTTPMethod:@"GET"]; [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { if (!error) { // success } else { // fail }} ]; 
+6
Mar 03 '16 at 14:36
source share

In Swift, you can declare several parameters as follows:

 let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "email, first_name, last_name, gender, picture"]) 
+4
Jul 10 '16 at 0:05
source share



All Articles