How to post tweet from iPhone without PIN using SA_OAuthTwitterEngine?

心已入冬 提交于 2019-12-11 00:46:10

问题


I am developing a iPhone application which sends tweets to twitter. For this I am using SA_OAuthTwitterEngine + MGTwitterEngine classes.

I register applicaiton to www.twitter.com/apps and pass Consumer key and Consumer secret to controller my code is this.

if(!_engine){
    _engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
    _engine.consumerKey    = slPcFUjUh5y1hex0zvEhPg;
    _engine.consumerSecret = u6ydovMdP9yeiVqDukVhIzZPgJR9XDPUwfxymzNs;  
}

UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];

if (controller){
    [self presentModalViewController: controller animated: YES];
    intTwitterFlag = 1;
}

Previously on twitter.com/apps I select Application type = client and my application will generate PIN and accessToken. But when i change my Application type = Browser it cannot generate PIN and accessToken.

Previously when application type is client i am giving user name and password and then control return to my application from the webview but now after entering user name and password it cannot dismissModalViewController but showing Select and Copy the PIN.

Thank you for your time and any help you can give me!


回答1:


Its better to use xAuth route for mobile apps

http://dev.twitter.com/pages/xauth

check XAuthTwitterEngine which implements xauth for the MGTwitterEngine




回答2:


Here it is:just replace the method in SA_OAuthTwitterController.m:

- (void) webViewDidFinishLoad: (UIWebView *) webView {
    _loading = NO;
    //[self performInjection];
    if (_firstLoad) {
        [_webView performSelector: @selector(stringByEvaluatingJavaScriptFromString:) withObject: @"window.scrollBy(0,200)" afterDelay: 0];
        _firstLoad = NO;
    } else {
        /*
        NSString                    *authPin = [self locateAuthPinInWebView: webView];
        NSLog(@"authPin: %@", authPin);
        if (authPin.length) {
            [self gotPin: authPin];
            return;
        }

        NSString                    *formCount = [webView stringByEvaluatingJavaScriptFromString: @"document.forms.length"];

        if ([formCount isEqualToString: @"0"]) {
            [self showPinCopyPrompt];
        }*/

        //*****************************************************
        //  This is to bypass the pin requirement 
        //  in case the call back URL is set in Twitter settings
        //*****************************************************     
        [_engine requestAccessToken];
        if ([_delegate respondsToSelector: @selector(OAuthTwitterController:authenticatedWithUsername:)])
        {
            [_delegate OAuthTwitterController: self authenticatedWithUsername: _engine.username];

        }
        [self performSelector: @selector(dismissModalViewControllerAnimated:) withObject: (id) kCFBooleanTrue afterDelay: 1.0];

        //[self dismissModalViewControllerAnimated:YES];
    }
    [UIView beginAnimations: nil context: nil];
    _blockerView.alpha = 0.0;
    [UIView commitAnimations];

    if ([_webView isLoading]) {
        _webView.alpha = 0.0;
    } else {
        _webView.alpha = 1.0;
    }
}



回答3:


I too faced the same issue, and i just removed callback url from the twitter app settings. For my surprise login proceeds without any issue.




回答4:


The replacement for this method

(void) webViewDidFinishLoad: (UIWebView *) webView

in the class SA_OAuthTwitterController.m works well.



来源:https://stackoverflow.com/questions/5405665/how-to-post-tweet-from-iphone-without-pin-using-sa-oauthtwitterengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!