0

我试图弄清楚这个错误意味着什么......

我正在尝试通过 Facebook sdk 获取用户信息。我只需要他们的电子邮件和姓名

Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0xde94ad0 {error=<CFBasicHash 0xde7d100 [0x3f616650]>{type = mutable dict, count = 3,
entries =>
    2 : <CFString 0xde722a0 [0x3f616650]>{contents = "type"} = <CFString 0xdeba1a0 [0x3f616650]>{contents = "OAuthException"}
    3 : <CFString 0xde6ba20 [0x3f616650]>{contents = "message"} = <CFString 0xdeb12a0 [0x3f616650]>{contents = "An active access token must be used to query information about the current user."}
    6 : <CFString 0xde74c40 [0x3f616650]>{contents = "code"} = 2500
}
}

我的基本代码...(在我的 viewDidLoad 下方)

facebook = [[Facebook alloc] initWithAppId:@"random#123456" andDelegate:self];

    [self login];

(在我的登录方法下面)

- (void) login {
    NSArray *permissionsArray = [NSArray arrayWithObjects:@"email", nil];
    [facebook authorize:permissionsArray];
}

(和我的 Facebook 请求方法......)

- (void)request:(FBRequest *)request didLoad:(id)result {
    NSLog(@"Inside didLoad");
    if ([result isKindOfClass:[NSArray class]]) {
        result = [result objectAtIndex:0];
    }
    // When we ask for user infor this will happen.
    if ([result isKindOfClass:[NSDictionary class]]){
        //NSDictionary *hash = result;
        NSLog(@"Name: %@", [result objectForKey:@"name"]); 
    }
    if ([result isKindOfClass:[NSData class]])
    {
        NSLog(@"Profile Picture");
        //[profilePicture release];
        //profilePicture = [[UIImage alloc] initWithData: result];
    }
    NSLog(@"request returns %@",result);
    //if ([result objectForKey:@"owner"]) {}

};

- (void)request:(FBRequest *)request didFailWithError:(NSError *)error{ 
    NSLog(@"%@",error);
}

我真的很困惑为什么我会收到错误以及我需要更改或添加什么才能修复它......

有任何想法吗?

编辑:我的请求代码:::

- (IBAction)requestFBFriends:(id)sender {
    NSLog(@"HERE");
    [facebook requestWithGraphPath:@"me/friends" andDelegate:self];
}
4

2 回答 2

0

如果您在模拟器/设备上运行应用程序尝试清理构建并全新安装应用程序。当前错误可能是由于不再有效/已撤销的访问令牌无法访问用户数据。希望能帮助到你!!!

于 2012-07-21T14:20:16.967 回答
0

以下是获取姓名和电子邮件的方法...我没有对其进行测试,所以如果它不起作用,请告诉我,我会找出问题所在。

如果您没有有效的访问令牌,则发送请求的方法需要进行身份验证

-(void)getUserFBInfo
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
        self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![self.facebook isSessionValid]) {
        NSLog(@"auth");
        [self.facebook authorize:[NSArray arrayWithObject:@"email"]];
    } else {
        [self apiFQLIMe];
    }
}


#pragma mark -
#pragma mark FBSessionDelegate

/**
 * Called when the user successfully logged in.
 */
- (void)fbDidLogin
{
    [self reportAction:@"FB allowed"];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[self.facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[self.facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
    [self apiFQLIMe];
}

/**
 * Called when the user dismissed the dialog without logging in.
 */
- (void)fbDidNotLogin:(BOOL)cancelled
{
    NSLog("did not login");
}

/**
 * Called after the access token was extended. If your application has any
 * references to the previous access token (for example, if your application
 * stores the previous access token in persistent storage), your application
 * should overwrite the old access token with the new one in this method.
 * See extendAccessToken for more details.
 */
- (void)fbDidExtendToken:(NSString*)accessToken
               expiresAt:(NSDate*)expiresAt
{
    NSLog(@"token extended");
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:accessToken forKey:@"FBAccessTokenKey"];
    [defaults setObject:expiresAt forKey:@"FBExpirationDateKey"];
    [defaults synchronize];
}

/**
 * Called when the user logged out.
 */
- (void)fbDidLogout
{
    NSLog("did logout")
}

/**
 * Called when the current session has expired. This might happen when:
 *  - the access token expired
 *  - the app has been disabled
 *  - the user revoked the app's permissions
 *  - the user changed his or her password
 */
- (void)fbSessionInvalidated
{
    [self.facebook authorize:[NSArray arrayWithObject:@"email"]];
}

#pragma mark -
#pragma mark FBRequestDelegate



- (void)apiFQLIMe {
    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"SELECT name, first_name, middle_name, last_name, username, contact_email FROM user WHERE uid=me()", @"query",
                               nil];
    [self.facebook requestWithMethodName:@"fql.query"
                               andParams:params
                           andHttpMethod:@"POST"
                             andDelegate:self];
}


/**
 * Called when the Facebook API request has returned a response.
 *
 * This callback gives you access to the raw response. It's called before
 * (void)request:(FBRequest *)request didLoad:(id)result,
 * which is passed the parsed response object.
 */
- (void)request:(FBRequest *)request didReceiveResponse:(NSURLResponse *)response
{
    DLog(@"received response");
}

/**
 * Called when a request returns and its response has been parsed into
 * an object.
 *
 * The resulting object may be a dictionary, an array or a string, depending
 * on the format of the API response. If you need access to the raw response,
 * use:
 *
 * (void)request:(FBRequest *)request
 *      didReceiveResponse:(NSURLResponse *)response
 */
- (void)request:(FBRequest *)request didLoad:(id)result 
{
    NSLog(@"%@",result);
    // check the log to know how you receive the result
}

/**
 * Called when an error prevents the Facebook API request from completing
 * successfully.
 */
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error 
{
    NSLog(@"Err message: %@", [[error userInfo] objectForKey:@"error_msg"]);
    NSLog(@"Err code: %d", [error code]);
}

如果您有问题,请在评论中提问

于 2012-07-22T22:05:10.260 回答