2

我正在尝试在我的应用程序中获取 facebook 用户的名称,但我得到了

{"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}

我的代码是:-

viewdidload

facebook = [[Facebook alloc] initWithAppId:@"233350100117670" andDelegate:self];    
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"])
{
    facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
NSArray *permissions =  [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", @"offline_access",nil] retain];
[facebook authorize:permissions];

if (![facebook isSessionValid])
{
    [facebook authorize:nil];
}

在那之后:-

- (void)request:(FBRequest *)request didFailWithError:(NSError *)error
{
    NSLog(@"%@", [error localizedDescription]);
    NSLog(@"Err details: %@", [error description]);
}

- (void)request:(FBRequest*)request didLoadRawResponse:(NSData*)data
{
    NSString *response = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
    NSLog(@"%@", response);
    [response release];
}

- (void) request:(FBRequest*)request didLoad:(id)result
{
    if ([result isKindOfClass:[NSDictionary class]])
    {
        NSString *email = [result objectForKey: @"email"];
        fbUserName = [result objectForKey: @"name"];
        NSString *facebookId = [result objectForKey: @"id"];
        NSString* title=[NSString stringWithFormat:@"%@ has won a gold medal on Olympedia quiz",fbUserName];
        NSMutableDictionary *params = 
        [NSMutableDictionary dictionaryWithObjectsAndKeys:title, @"name",@"Feed Dialogs of Olympedia.", @"caption",@"Check out Olmpedia Dialogs.", @"description",@"http://www.facebook.com/olympedia", @"link",@"http://bit.ly/PdpRSD", @"picture",nil];  
        [facebook dialog:@"feed" andParams:params andDelegate:self];
   }
}

在共享按钮上单击:-

- (IBAction)shareOnFacebook:(id)sender
{
    NSLog(@"Posting message");

    [facebook requestWithGraphPath:@"me" andDelegate:self];
}

请帮忙,因为我试图解决这个问题几个小时。强文本

4

0 回答 0