不能执行它,甚至试图通过认证数据
像消费者密钥,消费者密钥,令牌,但结果是一样的.
我能够登录和接收twitter身份验证令牌,但无法获取用户详细信息.
以下代码由我使用(我正在使用MGtwitter引擎):
NSMutableURLRequest *request =[[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:[Nsstring stringWithFormat:@"https://API.twitter.com/1.1/users/show.Json?screen_name=%@",username]]];NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];Nsstring *returnString = [[Nsstring alloc]initWithData:returnData enCoding:NSUTF8StringEnCoding]; NSError *err = nil;twitterLogin = [NSJsONSerialization JsONObjectWithData:[returnString dataUsingEnCoding:NSUTF8StringEnCoding] options:NSJsONReadingMutableContainers error:&err];
错误如下所示:
errors = ({ code = 215; message = "Bad Authentication data";} );解决方法 首先,您需要验证您的请求(获取权限).
第二,请参阅以下步骤:
下载FHSTwitterEngine Twitter图书馆.
2.将文件夹“FHSTwitterEngine”添加到您的项目中,然后添加#import“FHSTwitterEngine.h”.
3.将SystemConfiguration.framework添加到您的项目中.
Usage : 1.in the
[VIEwDIDLoad]
add the following code.
UIbutton *logIn = [UIbutton buttonWithType:UIbuttonTypeRoundedRect]; logIn.frame = CGRectMake(100,100,100); [logIn setTitle:@"Login" forState:UIControlStatenormal]; [logIn addTarget:self action:@selector(showLoginWindow:) forControlEvents:UIControlEventtouchUpInsIDe]; [self.vIEw addSubvIEw:logIn];[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:@"<consumer_key>" andSecret:@"<consumer_secret>"]; [[FHSTwitterEngine sharedEngine]setDelegate:self];
并且不要忘记导入代理FHSTwitterEngineAccesstokenDelegate.
you need to get the permission for your request,with the following method which will present Login window:
- (voID)showLoginWindow:(ID)sender { [[FHSTwitterEngine sharedEngine]showOAuthLoginControllerFromVIEwController:self withCompletion:^(BOol success) { NSLog(success?@"L0L success":@"O noes!!! Loggen faylur!!!"); }];}
当登录窗口出现时,输入您的Twitter用户名和密码来验证您的请求.
add the following methods to your code:
-(voID)vIEwWillAppear:(BOol)animated{ [super vIEwWillAppear:animated]; [[FHSTwitterEngine sharedEngine]loadAccesstoken]; Nsstring *username = [[FHSTwitterEngine sharedEngine]loggedInUsername];// self.engine.loggedInUsername; if (username.length > 0) { lbl.text = [Nsstring stringWithFormat:@"Logged in as %@",username]; [self ListResults]; } else { lbl.text = @"You are not logged in."; }}- (voID)storeAccesstoken:(Nsstring *)accesstoken { [[NSUserDefaults standardUserDefaults]setobject:accesstoken forKey:@"SavedAccesshttpBody"];}- (Nsstring *)loadAccesstoken { return [[NSUserDefaults standardUserDefaults]objectForKey:@"SavedAccesshttpBody"];}
4.Now you are ready to get your request,with the following method(in this method I created a
Hashtag
,to get thescreen_name
for example):
- (voID)ListResults { dispatch_async(GCDBackgroundThread,^{ @autoreleasepool { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; // the following line contains a FHSTwitterEngine method wich do the search. dict = [[FHSTwitterEngine sharedEngine]searchTweetsWithquery:@"#iOS" count:100 resultType:FHSTwitterEngineResultTypeRecent unil:nil sinceID:nil maxID:nil]; // NSLog(@"%@",dict); NSArray *results = [dict objectForKey:@"statuses"]; // NSLog(@"array text = %@",results); for (NSDictionary *item in results) { NSLog(@"text == %@",[item objectForKey:@"text"]); NSLog(@"name == %@",[[item objectForKey:@"user"]objectForKey:@"name"]); NSLog(@"screen name == %@",[[item objectForKey:@"user"]objectForKey:@"screen_name"]); NSLog(@"pic == %@",[[item objectForKey:@"user"]objectForKey:@"profile_image_url_https"]); } dispatch_sync(GCDMainThread,^{ @autoreleasepool { UIAlertVIEw *av = [[UIAlertVIEw alloc]initWithTitle:@"Complete!" message:@"Your List of followers has been fetched" delegate:nil cancelbuttonTitle:@"OK" otherbuttonTitles:nil]; [av show]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; } }); } });}
就这样.
我从搜索查询中获取了screen_name,您可以使用以下方法获取用户的时间轴:
// statuses/user_timeline- (ID)getTimelineForUser:(Nsstring *)user isID:(BOol)isID count:(int)count;- (ID)getTimelineForUser:(Nsstring *)user isID:(BOol)isID count:(int)count sinceID:(Nsstring *)sinceID maxID:(Nsstring *)maxID;
而不是上面的搜索方法.
注意:请参阅FHSTwitterEngine.h以了解需要使用的方法.
注意:获取< consumer_key>和< consumer_secret>您需要访问这个link 在Twitter上注册您的应用程序.
以上是内存溢出为你收集整理的iphone – 如何使用twitter api v1.1(Twitter错误215)获取用户详细信息全部内容,希望文章能够帮你解决iphone – 如何使用twitter api v1.1(Twitter错误215)获取用户详细信息所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)