2013-06-28 4 views
2

나는이 작업을 수행하는 데 사용 :지금 iOS에서 Twitter 프로필 사진 URL을 얻으려면 어떻게해야하나요?

NSString * strPictureURL = [NSString stringWithFormat:@"https://api.twitter.com/1/users/profile_image?screen_name=%@&size=bigger",strUsername.RobustURLEncodedString]; 

https://api.twitter.com/1/users/profile_image?screen_name=username&size=bigger

더 이상 더 이상 작동합니다. Twitter가 해당 API를 사용 중지합니다. 이미 인증을 받았습니다. 그럼 어떻게 알 수 있니?

답변

2

버전 사용 설정해야합니다.

Configuration은 매우 간단합니다 :

[[Twitter sharedInstance] startWithConsumerKey:@"_key_" consumerSecret:@"_secret_"]; 
[Fabric with:@[[Twitter sharedInstance]]]; 

그냥 사용 후 :

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) { 
    if (session) { 
     NSString *userID = [Twitter sharedInstance].sessionStore.session.userID; 
     TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:userID]; 
     [client loadUserWithID:userID completion:^(TWTRUser *user, NSError *error) { 
      NSLog(@"Profile image url = %@", user.profileImageLargeURL); 
     }]; 
    } else { 
     NSLog(@"error: %@", error.localizedDescription); 
    } 
}]; 
+2

이 코드 스 니펫에는 많은 구성 요소가 없습니다. – AddisDev

+0

완벽하게 작동합니다! –

1

는 대신 버전 1의

NSString * strPictureURL = [NSString stringWithFormat:@"https://api.twitter.com/1.1/users/profile_image?screen_name=%@&size=bigger",strUsername.RobustURLEncodedString]; 

는,이 그것을

  NSDictionary * resp = [NSJSONSerialization JSONObjectWithData:responseData 
                 options:0 
                 error:&jsonError]; 


      self.strUsername = [resp objectForKey:@"screen_name"]; 
      NSString * strPictureURL = [resp objectForKey:@"profile_image_url"]; 
      strPictureURL = [strPictureURL stringByReplacingOccurrencesOfString:@"_normal" withString:@""]; 
      self.strPictureURL = strPictureURL; 
+1

그 코드 https://api.twitter.com/1.1/users/profile_image?screen_name=teguh123&size=bigger 작동하지 않습니다. –