从Google+圈子iOS获取人员

时间:2016-04-07 11:10:46

标签: ios google-plus google-signin google-authentication google-people

我正在尝试检索用户圈子中的人物。由于GPPSignin已被删除,我使用GIDSignIn进行登录。但是GIDSignIn提供的身份验证是GIDAuthentication类型,不能在GTLServicePlus中使用

我已成功使用GIDSignInButton登录。这是我检索人员列表的代码

GTLServicePlus* plusService = [[[GTLServicePlus alloc] init] autorelease];
plusService.retryEnabled = YES;

[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];  //Problem is here
 GTLQueryPlus *query =
 [GTLQueryPlus queryForPeopleListWithUserId:@"me"
                                collection:kGTLPlusCollectionVisible];
[plusService executeQuery:query
    completionHandler:^(GTLServiceTicket *ticket,
                        GTLPlusPeopleFeed *peopleFeed,
                        NSError *error) {
        if (error) {
          GTMLoggerError(@"Error: %@", error);
        } else {
          // Get an array of people from GTLPlusPeopleFeed
          NSArray* peopleList = [peopleFeed.items retain];
        }
    }];

1 个答案:

答案 0 :(得分:0)

所以我目前正在通过手动创建GTMOAuth2Authentication对象并为其分配所需的值来解决此问题。这是我目前的代码。

func fetchGPlusContacts() {

    let plusService = GTLServicePlus()
    plusService.retryEnabled = true

    let user = signIn.currentUser
    let auth = GTMOAuth2Authentication()

    auth.clientID = signIn.clientID
    auth.userEmail = user.profile.email
    auth.userID = user.userID
    auth.accessToken = user.authentication.accessToken
    auth.refreshToken = user.authentication.refreshToken
    auth.expirationDate = user.authentication.accessTokenExpirationDate

    plusService.authorizer = auth

    let query = GTLQueryPlus.queryForPeopleListWithUserId("me", collection: kGTLPlusCollectionConnected) as! GTLQueryPlus


    plusService.executeQuery(query) { (ticket, peopleFeed, error) in
        if (error != nil) {
            print("error: \(error.description)")

            if (self.delegate != nil) {
                if self.delegate?.failedFetchFriendsFromGoogle != nil {
                    self.delegate!.failedFetchFriendsFromGoogle!(error)
                }
            }
        }
        else {
            if let peopleFd = peopleFeed as? GTLPlusPeopleFeed {
                var items : [GTLPlusPerson] = []
                if let itms = peopleFd.items() as? [GTLPlusPerson] {
                    items = itms
                }
            }
        }
    }
}

我仍在寻找执行此任务的正确方法。