gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 20:34:06 24 4
gpt4 key购买 nike

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

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

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 View 返回到我的应用程序,但现在输入用户名和密码后,它无法关闭 ModalViewController,但会显示选择并复制 PIN。

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

最佳答案

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

关于iphone - 如何使用 SA_OAuthTwitterEngine 在没有 PIN 的情况下从 iPhone 发布推文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5405665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com