0

我想从 facebook 获取用户信息。我为此使用 FBConnect APi。

4

3 回答 3

1

您应该将其用于 FBConnect,这对您有用。

  - (void)request:(FBRequest*)request didLoad:(id)result {
    if ([request.method isEqualToString:@"facebook.fql.query"]) {
    NSArray* users = result;
    NSDictionary* user = [users objectAtIndex:0];
    NSString* name = [user objectForKey:@"name"];
    self.username = name;       

    if (self.post) {
        [self postToWall];
        self.post = NO;
      }
     }
     }


 - (void)postToWall 
 {
    FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
    dialog.userMessagePrompt = @"Enter your message:";
    dialog.attachment = [NSString stringWithFormat:@"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"];
    [dialog show];
 }
于 2012-05-03T06:05:41.393 回答
0

要从 facebook 获取信息,您必须使用 FBGraph API。希望这个链接可以帮助你。

于 2012-05-03T06:04:46.027 回答
0

试试这个希望它会帮助你: -

- (void)request:(FBRequest*)request didLoadRawResponse:(NSData*)data
{

    NSString *profileString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSMutableDictionary *userinfo = [[profileString JSONValue] mutableCopy];//1451571176

    [[NSUserDefaults standardUserDefaults] setObject:userinfo forKey:@"USER_INFO"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    NSLog(@"user info:%@",userinfo);

    userDictionary = [[NSUserDefaults standardUserDefaults] valueForKey:@"USER_INFO"];
    NSString *userIDString = [NSString stringWithFormat:[userDictionary valueForKey:@"id"]];
    NSLog(@"User: %@",userIDString);
}

希望它有所帮助。如果没有,请澄清。谢谢:)

于 2012-05-03T06:04:54.957 回答