开发者

how to get the user name of the currently logged in user using latest facebook graph api

i ve created a facebook application using facebook graph api what i want is to get the user name of the currently logged in user .below is the code

  开发者_JS百科  -(IBAction)bomb
{

    facebook = [[Facebook alloc] initWithAppId:@"109133762519851"];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![facebook isSessionValid]) {
        [facebook authorize:nil delegate:self];
    }


}

    - (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    NSLog(@"facebook:%@",defaults);



    [facebook dialog:@"stream.publish" andParams:params andDelegate:self];  */
    NSMutableDictionary *fbArguments = [[NSMutableDictionary alloc] init];

    NSString *wallPost = @"wat de heck";
    NSString *linkURL  = @"http://www.supersite.com";
    NSString *imgURL   = @"http://www.supersite.com/image.jpg";

    [fbArguments setObject:wallPost forKey:@"message"];
    [fbArguments setObject:linkURL  forKey:@"link"];
    [fbArguments setObject:imgURL   forKey:@"picture"];

    //NSLog(@"username:%@",facebook.);
    [facebook requestWithGraphPath:@"me/feed" 
                         andParams:fbArguments
                     andHttpMethod:@"POST"
                       andDelegate:self];
}


#pragma mark FBRequestDelegate methods
- (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"];
        username = name;
        [username retain];
}

- (void)getFacebookName
{
    NSString* fql = [NSString stringWithFormat:@"select uid,name from user where uid == %lld", session.uid];
    NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
    [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
}

you need to import these 2 classes and implement this protocal

#import "FBConnect/FBConnect.h"
#import "FBConnect/FBSession.h"
FBRequestDelegate
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜