如何使用FBConnect从Facebook获取信息

时间:2012-05-03 05:57:38

标签: iphone fbconnect

我想从facebook获取用户信息。我正在使用FBConnect APi。

3 个答案:

答案 0 :(得分: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];
 }

答案 1 :(得分:0)

要从Facebook获取信息,您必须使用FBGraph API。希望Link可以帮到你。

答案 2 :(得分: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);
}

希望它有所帮助。如果不是那么请澄清。谢谢:)