1

私はアプリをやっていて、ユーザーが Fb から登録できるようにしたいので、Facebook から名前、電子メール、性別を取得することを考えましたが、データを取得する方法が見つかりません。

これが私のコードの例です:

// extract the id's for which we will request the profile
    NSArray *fbids = [NSArray arrayWithObjects:@"name",@"email",@"gender", nil];

    // create the connection object
    FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];

    // for each fbid in the array, we create a request object to fetch
    // the profile, along with a handler to respond to the results of the request
    for (NSString *fbid in fbids) {

        // create a handler block to handle the results of the request for fbid's profile
        FBRequestHandler handler = 
        ^(FBRequestConnection *connection, id result, NSError *error) {

            // output the results of the request
            [self requestCompleted:connection forFbID:fbid result:result error:error];

        };

        // create the request object, using the fbid as the graph path
        // as an alternative the request* static methods of the FBRequest class could
        // be used to fetch common requests, such as /me and /me/friends
        FBRequest *request = [[FBRequest alloc] initWithSession:FBSession.activeSession
                                                      graphPath:fbid];

        // add the request to the connection object, if more than one request is added
        // the connection object will compose the requests as a batch request; whether or
        // not the request is a batch or a singleton, the handler behavior is the same,
        // allowing the application to be dynamic in regards to whether a single or multiple
        // requests are occuring
        [newConnection addRequest:request completionHandler:handler];
    }



// FBSample logic

// 結果を報告します。リクエストごとに 1 回呼び出されます。- (void)requestCompleted:(FBRequestConnection *)connection forFbID:fbID result:(id)result error:(NSError *)error {

// not the completion we were looking for...
if (self.requestConnection &&
    connection != self.requestConnection) {
    return;
}

// clean this up, for posterity
self.requestConnection = nil;

NSString *nombre;
NSString *localizacion;
NSString *genero;
NSString *cumpleanyos;
NSString *email;

if (error) {
    // error contains details about why the request failed
    nombre = error.localizedDescription;
} else {
    // result is the json response from a successful request
    NSDictionary *dictionary = (NSDictionary *)result;
    // we pull the name property out, if there is one, and display it
    nombre = (NSString *)[dictionary objectForKey:@"name"];
    localizacion = (NSString *)[dictionary objectForKey:@"location"];
    genero = (NSString *)[dictionary objectForKey:@"gender"];
    cumpleanyos = (NSString *)[dictionary objectForKey:@"birthday"];
    email = (NSString *)[dictionary objectForKey:@"email"];
}

}

4

1 に答える 1

0

問題は次のとおりだと思います。

NSArray *fbids = [NSArray arrayWithObjects:@"name",@"email",@"gender", nil];

「FaceBook User Ids」を使用する必要があります。次を試してください。

NSString *camposUsuario = @"4,6";
NSArray *fbids = [camposUsuario componentsSeparatedByString:@","];

この場合、「4」と「6」は「FaceBook ユーザー ID」です。

特定のユーザーの情報をリクエストする場合は、そのユーザーの「FaceBook ユーザー ID」を知る必要があります。

于 2012-08-31T07:26:08.480 に答える