简体   繁体   中英

Parse Linkedin API call

Here is what it looks like in the Mainviewcontroller.

I have two separate classes, LinkedInUser and _User. The accessToken is stored in the LinkedInUser not in the _User. There is a pointer in the LinkedInUser class called "user" which points to the "objectID" in _User. I want to retrieve the accessToken from LinkedInUser but overtime I try a query it returns no results and when I run the code below, it results in a null. What am I doing wrong and how can I fix it?

  [PFLinkedInUtils logInWithBlock:^(PFUser *user, NSError *error) {
    NSLog(@"User: %@, Error: %@", user, error);

    PFObject *linkedin = [PFObject objectWithClassName:@"LinkedInUser"];

    NSString *accessToken = linkedin[@"accessToken"];

        [PFLinkedInUtils.linkedInHttpClient GET:[NSString stringWithFormat:@"https://api.linkedin.com/v1/people/~:(blahblahblah)?oauth2_access_token=%@&format=json", accessToken] parameters:nil success:^(AFHTTPRequestOperation *operation, id result)

This line:

PFObject *linkedin = [PFObject objectWithClassName:@"LinkedInUser"];

is creating a new instance of a LinkedInUser object. It will not have a value for the accessToken property. Instead you should query Parse for the existing object associated with the user.

Additionally, if you are able to change your data model slightly, it might be better to have a pointer on _User that references the LinkedInUser . That way, you can just get that object directly without having to make another query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM