1

我正在尝试检索用户圈子中的用户。由于GPPSignin已被删除,因此我正在使用GIDSignIn进行登录。但由GIDSignIn提供的身份验证类型为GIDAuthentication,不能用于GTLServicePlus从Google+中获得用户圈子iOS

我已成功使用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]; 
     } 
    }]; 
+0

您是否解决了此问题? –

+0

@AlexanderVolkov我目前正在手动创建GTMOAuth2Authentication对象并为其分配所有必需的字段,clientID,userEmail,userID,accessToken,refreshToken,expirationDate。它正在工作。 –

+0

因此,您正在使用两种框架 - 旧的Goolge Plus SDK和Google Sign-In,是否正确?你能举个例子吗?您是否尝试过使用Google Plus Web API或? –

回答

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

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

相关问题