如何使用 SA_OAuthTwitterEngine 在没有 PIN 的情况下从 iPhone 发布推文?

发布于 2024-10-25 00:23:22 字数 896 浏览 3 评论 0原文

我正在开发一个 iPhone 应用程序,它将推文发送到 Twitter。为此,我使用 SA_OAuthTwitterEngine + MGTwitterEngine 类。

我将应用程序注册到 www.twitter.com/apps 并传递消费者密钥和消费者秘密来控制我的代码是这样的。

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

之前在 twitter.com/apps 上,我选择应用程序类型 = 客户端,我的应用程序将生成 PIN 和 accessToken。但是当我更改应用程序类型 = 浏览器时,它无法生成 PIN 和 accessToken。

以前,当应用程序类型为客户端时,我提供用户名和密码,然后控制从 Web 视图返回到我的应用程序,但现在输入用户名和密码后,它无法关闭 ModalViewController,但显示选择并复制 PIN。

感谢您的宝贵时间以及您能给我的任何帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

巨坚强 2024-11-01 00:23:22

这里是:只需替换 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;
    }
}

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;
    }
}
得不到的就毁灭 2024-11-01 00:23:22

我也遇到了同样的问题,我刚刚从 Twitter 应用程序设置中删除了回调 url。令我惊讶的是,登录过程没有任何问题。

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.

汹涌人海 2024-11-01 00:23:22

此方法的替换效果很好。

(void) webViewDidFinishLoad: (UIWebView *) webView

SA_OAuthTwitterController.m 类中

The replacement for this method

(void) webViewDidFinishLoad: (UIWebView *) webView

in the class SA_OAuthTwitterController.m works well.

感性不性感 2024-11-01 00:23:22

最好对移动应用使用 xAuth 路由

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

检查 XAuthTwitterEngine,它为 MGTwitterEngine 实现了 xauth

Its better to use xAuth route for mobile apps

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

check XAuthTwitterEngine which implements xauth for the MGTwitterEngine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文