[英]Twitter integrated in Iphone App
我用了MGTwitterEngine
尝试登录然后请求失败错误
错误详情
连接标识符6260FAFD-AE4E-4F05-AE67-FFA1DA18578F
错误说明操作无法完成。 (HTTP错误401。)
错误的用户信息 ({body =“ \\ n \\ n不允许客户端应用程序使用xAuth。\\ n / oauth / access_token \\ n \\ n”; response =“”;})
任何想法
-阿米特·巴坦(Amit Battan)
Twitter不再支持基本身份验证。 您可以使用Twitter-oAuth-iPhone 。 它使用MGTwitterEngine添加了oAuth。 也包括一个演示代码项目。 但是,您将需要SDK> = 3.2来编译最新版本。
您需要向Twitter API团队要求提供xAuth的问题,以提供应用程序的详细信息。 在不需要oAuth的情况下。 您将需要在Twitter Dev中创建一个应用程序,然后需要使用项目中的密钥。 就这样。
MGTwitterEngine在这一点上已经过时,因为它不使用xAuth / oAuth。 请参阅有关将MGTwitterEngine与xAuth结合使用的教程:
OAuth不需要Twitter的许可。 但是XAuth是必需的。
我没有在Twitter的官方文档中使用MGTwitterEngine ,而是使用C刮擦了一个客户端,以计算现时和签名,然后使用工具cURL,然后可以获得oauth_token和token_secret。
有关cURL的其他消息是,您必须已在Twitter中创建了您的应用程序,您可以在应用程序中使用OAuth tool
(不需要是正在使用的当前应用程序)设置。 如果twitter中的应用程序不是您当前的应用程序,则应首先生成cURL命令行。 将“ 请求设置”设置为POST
,将“ 请求URI”设置为http://api.twitter.com/oauth/request_token
,将其他设置保留为默认设置,然后单击页面底部的按钮,然后看到cURL命令,好像那:
curl --request 'POST' 'http://api.twitter.com/oauth/request_token' --header 'Authorization: OAuth oauth_consumer_key="your_consumer_key", oauth_nonce="your_random_string", oauth_signature="your_signature", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1329273306", oauth_token="451145411-AxGXG8xNdW1Eymwx85hs3sc1OE3NYsXe578AUtPe", oauth_version="1.0"' --verbose
用您的替换oauth_consumer_key
, oauth_timestamp
和oauth_signature
,删除oauth_token
及其值,将命令复制到您的cmd
或shell
并执行它。 另一个重要的技巧是,您必须在Authorization
显式标记oauth_callback
,并将值设置为oob
:
auth_callback="oob"
如果您的consumer_key
和oauth_signature
是正确的,则此步骤将不会导致Client application is not permitted to use xAuth
错误。
@taskino或我正在使用的代码...我已经在Twitter上创建了应用程序
控制器.h文件
#import <UIKit/UIKit.h>
#import "MGTwitterEngine.h"
@class OAToken;
@interface TwitterTestViewController : UIViewController <MGTwitterEngineDelegate> {
MGTwitterEngine *twitterEngine;
OAToken *token;
}
@end
控制器.m文件
#import "TwitterTestViewController.h"
@implementation TwitterTestViewController
- (void)awakeFromNib{
// Put your Twitter username and password here:
NSString *username = @"amit_bursys";
NSString *password = @"mypassword";
NSString *consumerKey = @"my_key";
NSString *consumerSecret = @"my_seret";
if (! username || ! password || !consumerKey || !consumerSecret) {
NSLog(@"You forgot to specify your username/password/key/secret in AppController.m, things might not work!");
NSLog(@"And if things are mysteriously working without the username/password, it's because NSURLConnection is using a session cookie from another connection.");
}
twitterEngine = [[MGTwitterEngine alloc] initWithDelegate:self];
[twitterEngine setUsesSecureConnection:NO];
[twitterEngine setConsumerKey:consumerKey secret:consumerSecret];
[twitterEngine setUsername:username];
[twitterEngine getXAuthAccessTokenForUsername:username password:password];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
#pragma mark MGTwitterEngineDelegate methods
- (void)requestSucceeded:(NSString *)connectionIdentifier{
NSLog(@"Request succeeded for connectionIdentifier = %@", connectionIdentifier);
}
- (void)requestFailed:(NSString *)connectionIdentifier withError:(NSError *)error{
NSLog(@"Request failed for connectionIdentifier = %@, error = %@ (%@)",
connectionIdentifier,
[error localizedDescription],
[error userInfo]);
}
- (void)statusesReceived:(NSArray *)statuses forRequest:(NSString *)connectionIdentifier{
NSLog(@"Got statuses for %@:\r%@", connectionIdentifier, statuses);
}
- (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier{
NSLog(@"Got direct messages for %@:\r%@", connectionIdentifier, messages);
}
- (void)userInfoReceived:(NSArray *)userInfo forRequest:(NSString *)connectionIdentifier
{
NSLog(@"Got user info for %@:\r%@", connectionIdentifier, userInfo);
}
@end
和代码日志是
2010-12-21 11:14:31.533 TwitterTest[734:207] Request failed for connectionIdentifier = D28BD476-7315-4510-B51A-968E516D169D, error = The operation couldn’t be completed. (HTTP error 401.) ({
body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n <request>/oauth/access_token</request>\n <error>Client application is not permitted to use xAuth.</error>\n</hash>\n";
response = "<NSHTTPURLResponse: 0x6022470>";
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.