[英]iPhone Facebook SDK Error
I'm trying to figure out what this error means... 我正在尝试找出此错误的含义...
I'm trying to get user information via Facebook sdk. 我正在尝试通过Facebook SDK获取用户信息。 All I need is their email and name
我只需要他们的电子邮件地址和姓名
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
}
}
My basic code... (below in my viewDidLoad) 我的基本代码...(在我的viewDidLoad中)
facebook = [[Facebook alloc] initWithAppId:@"random#123456" andDelegate:self];
[self login];
(below in my login method) (在我的登录方法下面)
- (void) login {
NSArray *permissionsArray = [NSArray arrayWithObjects:@"email", nil];
[facebook authorize:permissionsArray];
}
(and my Facebook request methods...) (以及我的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);
}
I'm really confused to why I get an error and what I need to change or add in order to fix it... 我真的很困惑为什么我会收到错误以及我需要更改或添加的内容以修复该错误...
Any ideas? 有任何想法吗?
EDIT: My request code::: 编辑:我的请求代码:::
- (IBAction)requestFBFriends:(id)sender {
NSLog(@"HERE");
[facebook requestWithGraphPath:@"me/friends" andDelegate:self];
}
If you are running the application on Simulator/device Try cleaning the build and fresh install the application. 如果您正在模拟器/设备上运行该应用程序,请尝试清理内部版本并重新安装该应用程序。 The current error might be due to inactive/revoked access token which is no longer valid to access user data.
当前错误可能是由于无效/已撤销的访问令牌所致,该令牌对于访问用户数据不再有效。 Hope it helps!!!
希望能帮助到你!!!
Here's how you can get the name and email... I didn't test it so if it doesn't work just tell and I'll find out the problem. 这是获取名称和电子邮件的方法...我没有对其进行测试,所以如果它不能正常工作,请告诉我,然后我将找出问题所在。
The method that sends the request needs to authenticate if you don't have a valid access token 如果您没有有效的访问令牌,则发送请求的方法需要进行身份验证
-(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]);
}
If you have questions ask them in the comments 如果您有任何疑问,请在评论中提问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.