iOS - 使用 Google SignIn SDK 获取名字和姓氏

iOS - Get first name and last name using Google SignIn SDK

我正在使用 Google 登录 SDK,它运行良好。我能够得到以下数据:

NSString *userId = user.userID;                  // For client-side use only!
NSString *idToken = user.authentication.idToken; // Safe to send to the server
NSString *name = user.profile.name;
NSString *email = user.profile.email;

如何检索名字和姓氏?还有其他信息,比如用户居住的城市等等?

您已经在 user.profile.name 中输入了名字和姓氏,这是全名。

其他信息,您可以拨打网络API:

GET https://www.googleapis.com/plus/v1/people/me?fields=aboutMe%2Cbirthday%2CcurrentLocation%2CplacesLived&key={YOUR_API_KEY}

您可以通过添加更多参数来获取其他信息。有关详细信息,Google 在这里解释

https://developers.google.com/+/web/api/rest/latest/people/get#examples

我也遇到了和你一样的问题。您无法从 Google SDK 中单独获取名字和姓氏。相反,您可以按如下方式手动完成,

NSString *name = user.profile.name;
NSArray *items = [name componentsSeparatedByString:@" "];   //take one array for splitting the string
NSString *fname = [items objectAtIndex:0];
NSString *lname = [items objectAtIndex:1];