1

我正在尝试检索用户圈子中的人。由于 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];
        }
    }];
4

1 回答 1

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
                }
            }
        }
    }
}

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

于 2016-04-14T06:48:34.680 回答