2011-08-22 51 views
0

我創建了一個使用facebook圖形API的Facebook應用程序我想要的是獲取當前登錄的用戶的用戶名。下面是代碼如何獲取當前登錄的用戶的用戶名使用最新的facebook圖形API

-(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]; 
} 

回答

0
#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]; 
} 

需要導入這2類和實現這個protocal

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

即時得到一個錯誤的DAT 「request.method是諾塔結構或聯合」 使用最新的小號 – kingston

+0

IM dk ..上面兩個類im無法導入 – kingston

+0

即時通訊不能找到當前登錄的用戶 – kingston

相關問題