2012-07-21 94 views
0

我想弄清楚這個錯誤的含義是什麼...iPhone Facebook SDK錯誤

我想通過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]; 
} 
+0

我不知道有關的權限驗證你正在使用,但在我的應用程序中,我使用「電子郵件」作爲唯一的權限,這使您可以訪問聯繫人電子郵件,名稱是一個基本的權限,所以你不需要指定它 – Moxy 2012-07-21 13:06:25

+0

@Moxy我改變了我的權限只有電子郵件,我仍然得到相同的錯誤... – 2012-07-21 13:08:12

+0

請問您可以添加您的請求代碼,還可以在哪裏調用它? – Moxy 2012-07-21 13:57:28

回答

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

如果你有問題問他們的意見

0

如果您運行的模擬器/設備上的應用嘗試清洗構建和全新安裝應用程序。目前的錯誤可能是由於不活動/撤銷的訪問令牌,它不再有效訪問用戶數據。 希望它有幫助!

+0

這沒有做到...... – 2012-07-21 19:06:57