获取Google个人资料API不会返回生日和性别键值

时间:2017-09-13 16:58:16

标签: ios objective-c ruby google-api google-people

@SuppressStaticInitializationFor(value = "so46196071.Base") // suppress the static in Base (note this is my package name) @PowerMockIgnore("javax.management.*") @RunWith(PowerMockRunner.class) @PrepareForTest({Module.class, ServiceA.class, ServiceB.class}) public class ModuleBisTest { private Module module; @Mock private ServiceA serviceA; @Mock private ServiceB serviceB; @Before public void setup() throws Exception { // MockitoAnnotations.initMocks(this); /* this is not needed => done by the runner */ PowerMockito.mockStatic(ServiceA.class); PowerMockito.when(ServiceA.class, "getInstance").thenReturn(serviceA); PowerMockito.mockStatic(ServiceB.class); PowerMockito.when(ServiceB.class, "getInstance").thenReturn(serviceB); module = new Module(); Whitebox.setInternalState(Base.class, "serviceA", serviceA); // set serviceA in Base "by hand" Whitebox.setInternalState(Base.class, "serviceB", serviceB); // set serviceB in Base "by hand" // I spy it because it has other methods I need to mock module = PowerMockito.spy(module); } // ...

在我的iOS应用中,我将范围设置为:

GPPSignIn *signIn;

此外,

signIn.scopes = @[@"https://www.googleapis.com/auth/plus.login",
                  @"https://www.googleapis.com/auth/plus.me",
                  @"https://www.googleapis.com/auth/plus.profile.emails.read", 
                  @"email",
                  @"profile",
                  @"https://www.googleapis.com/auth/user.birthday.read"];

尝试从Google获取signIn.shouldFetchGoogleUserEmail = YES; signIn.shouldFetchGooglePlusUser = YES; 。我得到并发送到服务器。

现在,我的服务器正在执行此操作:

access_token

在这里,client = OAuth2::Client.new('app_id', 'app_secret') access_token = OAuth2::AccessToken.new(client, access_token) profile_api_url = 'https://www.googleapis.com/plus/v1/people/me' response = access_token.get(profile_api_url) google_profile_res_body = JSON.parse(response.body) 有许多属性,但没有生日和性别。

任何人都有任何想法?请建议。提前谢谢。

干杯, 拉胡

1 个答案:

答案 0 :(得分:1)

可能问题是只有在字段设置为具有公开可见性的情况下才会返回生日和性别。不会返回私人可见性字段。

如果您使用与 G + People API 不同的 Google People API ,您应该可以获得https://www.googleapis.com/auth/user.birthday.read范围的私人生日。不幸的是,性别没有私人范围。

有关详细信息,请参阅https://developers.google.com/people/上的Google People API文档。