iPhone上的Facebook访问令牌错误

时间:2012-07-05 12:39:25

标签: iphone facebook facebook-graph-api

我想在我的应用程序中获取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];
}

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

0 个答案:

没有答案