简体   繁体   中英

iPhone - Twitter “Select and copy the PIN” issue

I want to enable "login with Twitter" option in my app.
For this I'm using Twitter-OAuth-iPhone library (do I really need all this library just to login?)

Anyway after user enter his twitter username & password and Authorize the app, I'm getting to a view with "Select and copy the PIN" message, and I'm stuck without anything to do..

What can I do to solve this?

This will help you:

- (NSString *)locatePin {
    NSString *pin = [[_theWebView stringByEvaluatingJavaScriptFromString:newPinJS]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    if (pin.length == 7) {
        return pin;
    } else {
        pin = [[_theWebView stringByEvaluatingJavaScriptFromString:oldPinJS]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

        if (pin.length == 7) {
            return pin;
        }
    }

    return nil;
}

add these after the @implementation of your class:

static NSString * const newPinJS = @"var d = document.getElementById('oauth-pin'); if (d == null) d = document.getElementById('oauth_pin'); if (d) { var d2 = d.getElementsByTagName('code'); if (d2.length > 0) d2[0].innerHTML; }";
static NSString * const oldPinJS = @"var d = document.getElementById('oauth-pin'); if (d == null) d = document.getElementById('oauth_pin'); if (d) d = d.innerHTML; d;";

and you need a library to login, this link provide an answer how to login if you need it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM