0

このエラーの意味を理解しようとしています...

FacebookSDKを介してユーザー情報を取得しようとしています。必要なのは彼らのメールアドレスと名前だけです

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 に答える