2015-12-16 58 views
2
- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user 
    withError:(NSError *)error { 
    NSString *userId = user.userID; 
    NSString *idToken = user.authentication.idToken; 
    NSString *name = user.profile.name; 
    NSString *email = user.profile.email; 
    //NSString *Url = user.profile.imageURL; 
} 

我試圖讓谷歌登錄用戶的詳細信息。 如何獲取profileImageUrl? 任何幫助將被apricated.thanks提前iOS google登錄profileImageURL

+0

[如何通過Google plus中的用戶ID獲取用戶圖像?](http://stackoverflow.com/questions/22406756/how-to-get-user-image-through-user-id-in -google-plus) –

回答

0

谷歌已定義一種方法來獲取配置文件圖像的URL爲iOS API。該方法是-(NSURL *) imageURLWithDimension:(NSUInteger) dimension。你只需要做到以下幾點:登錄後

使用此代碼:

if(user.profile.hasImage) 
{ 
    NSURL *imageURL = [user.profile imageURLWithDimension(50)]; //Give your desired dimenion in parameter. 
} 

這在Google API documentation定義。

如果您收到意外的,如過去一些用戶所見,請參閱此already answered question以解決此問題。但這不應該再次發生,因爲根據谷歌:

這是固定在我們剛剛發佈的2.3.1。

查看該bug的狀態here

並提出一個建議,將您的登錄成功代碼放入if(!error)子句中。現在你假設登錄失敗永遠不會發生。 (如果你已經這樣做了,但沒有在這裏顯示,請忽略此建議)。

+0

在'GIDProfileData *'類型的對象上找不到「Property'imageURLWithDimension'」 – karthi

+0

@karthi對於該錯字感到抱歉。我已經更新了代碼。這是一種方法而不是屬性,這就是錯誤的原因。現在應該工作! – NSNoob