0

Graph APIiOSプロジェクトで使用しています。問題は、Facebook ログイン webview でログイン資格情報を入力した後、リダイレクト URI でアクセス トークンが得られないことです。私は2日でこの問題に直面しています。2日前まで、私のアプリは正常に動作していました。

ログイン後に呼び出されるコードGraph APIは次のとおりです。

- (void)webViewDidFinishLoad:(UIWebView *)_webView {

    /**
     * Since there's some server side redirecting involved, this method/function will be called several times
     * we're only interested when we see a url like:  http://www.facebook.com/connect/login_success.html#access_token=..........
     */

    //get the url string
    NSString *url_string = [((_webView.request).URL) absoluteString];

    //looking for "access_token="
    NSRange access_token_range = [url_string rangeOfString:@"access_token="];

    //looking for "error_reason=user_denied"
    NSRange cancel_range = [url_string rangeOfString:@"error_reason=user_denied"];

    //it exists?  coolio, we have a token, now let's parse it out....
    if (access_token_range.length > 0) {

        //we want everything after the 'access_token=' thus the position where it starts + it's length
        int from_index = access_token_range.location + access_token_range.length;
        NSString *access_token = [url_string substringFromIndex:from_index];

        //finally we have to url decode the access token
        access_token = [access_token stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

        //remove everything '&' (inclusive) onward...
        NSRange period_range = [access_token rangeOfString:@"&"];

        //move beyond the .
        access_token = [access_token substringToIndex:period_range.location];

        //store our request token....
        self.accessToken = access_token;

        //remove our window
        UIWindow* window = [UIApplication sharedApplication].keyWindow;
        if (!window) {
            window = [[UIApplication sharedApplication].windows objectAtIndex:0];
        }

        [self.webView removeFromSuperview];

        //tell our callback function that we're done logging in :)
        if ( (callbackObject != nil) && (callbackSelector != nil) ) {
            [callbackObject performSelector:callbackSelector];
        }

        //the user pressed cancel
    } else if (cancel_range.length > 0) {
        //remove our window
        UIWindow* window = [UIApplication sharedApplication].keyWindow;
        if (!window) {
            window = [[UIApplication sharedApplication].windows objectAtIndex:0];
        }

        [self.webView removeFromSuperview];

        //tell our callback function that we're done logging in :)
        if ( (callbackObject != nil) && (callbackSelector != nil) ) {
            [callbackObject performSelector:callbackSelector];
        }

    }

      [activityindicatorview stopAnimating];
}

何が問題なのか誰か教えてください。前もって感謝します。

4

1 に答える 1

1

Facebook has changed his policies.

Item 4. Native iOS and Android apps must not use custom web views for Login (Effective October 2, 2013)

You should use Facebook Official SDK.

于 2013-10-06T21:05:21.627 に答える