2011-01-25 13 views
1

私はShareKitを使用しており、ユーザーがFacebookにログインしていることを確認しています。 Facebookのユーザー名を取得したい。ShareKitでは、どのようにしてユーザーのFacebookユーザー名を取得できますか?

SHKFacebook *facebook = [[SHKFacebook alloc] init]; 
[facebook getAuthValueForKey:@"username"]; 

getAuthValueForKey:方法は私には何も返しません。ここに私が試したものです。 Facebookのユーザー名を取得するにはどうしたらいいですか?

+0

この質問は頼まれた:のhttp:/ /stackoverflow.com/questions/4772378/getting-user-id-of-facebook-and-twitter-in-sharekitまだ答えがありません*残念なことに* –

答えて

4

get usernameにはFacebook Graph APIを使用できます。 FBConnectパッケージのFBSession.mクラスにメソッドを追加します。

#import "JSON.h" 

...........

static NSString *const kGraphAPIURL = @"https://graph.facebook.com/"; 
static NSString *const kFBGraphAPIUserName = @"name"; 

...........

// Get user name via Facebook GraphAPI. 
- (NSString *)getUserNameByUID:(FBUID)aUID { 

    NSString *userName_ = nil; 

    NSURL *serviceUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%qi", kGraphAPIURL, aUID]]; 

    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; 

    NSError *error = nil; 
    NSString *jsonString = [NSString stringWithContentsOfURL:serviceUrl encoding:NSUTF8StringEncoding error:&error]; 

    if (error != nil) { 
     NSLog(@"######### error: %@", error); 
    } 

    if (jsonString) { 

     // Parse the JSON into an Object and 
     // serialize its object to NSDictionary 
     NSDictionary *resultDic = [jsonString JSONValue]; 

     if (resultDic) { 
      userName_ = [resultDic valueForKey:kFBGraphAPIUserName]; 
     } 
    } 

    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

    return userName_; 
} 
+0

あなたのお返事ありがとうございます。 ShareKit APIを使用してユーザー名を取得できることを期待していますが、おそらくそれは不可能です。 –

+0

ここでkGraphAPIURL、kFBGraphAPIUserNameは何ですか、警告NSDictionary * resultDic = [jsonString JSONValue]を表示します。 NSStringが-JSONValue –

+0

静的NSString *に応答しない可能性があります。const kGraphAPIURL = @ "https://graph.facebook.com/"; 静的NSString * const kFBGraphAPIUserName = @ "name"; FBSession.mファイルの先頭に#import "JSON.h"を追加することを忘れないでください – berec

関連する問題