gpt4 book ai didi

iphone - 如何使用 iOS 5 的 iOS TWRequest 获取 Twitter 用户详细信息

转载 作者:行者123 更新时间:2023-11-28 20:16:20 26 4
gpt4 key购买 nike

如何使用适用于 iOS 5 的 TWRequest 获取 Twitter 用户详细信息,

TWRequest 工作得更早,我就是这样使用的

 NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/users/show.json"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:twittername,@"screen_name",nil];
request = [[TWRequest alloc] initWithURL:url
parameters:params
requestMethod:TWRequestMethodGET];

但最近,Twitter 关闭了 api version 1 并实现了 version 1.1,并且目前上述逻辑在 iOS 5 中不起作用,由于 API deprecation 可能...

我正在使用适用于 iOS 6 的 SLRequest,它工作完美,但我想知道我们如何在 iOS 5 中获取 Twitter 用户详细信息

最佳答案

试试这个:

   NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.1/users/show.json"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:twittername,@"screen_name",nil];
request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodGET];

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
NSArray *twitterAccounts = [accountStore accountsWithAccountType:twitterAccountType];

// Runing on iOS 6
if (NSClassFromString(@"SLComposeViewController") && [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
[accountStore requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *error)
{
if (granted)
{
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:parameters];

[request setAccount:[twitterAccounts lastObject]];

dispatch_async(dispatch_get_main_queue(), ^
{

[NSURLConnection sendAsynchronousRequest:request.preparedURLRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response1, NSData *data, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^
{
if (data)
{
[self loadData:data];
}
});
}];
});
}
}];
}
else if (NSClassFromString(@"TWTweetComposeViewController") && [TWTweetComposeViewController canSendTweet]) // Runing on iOS 5
{
[accountStore requestAccessToAccountsWithType:twitterAccountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if (granted)
{
TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:parameters requestMethod:TWRequestMethodGET];
[request setAccount:[twitterAccounts lastObject]];

dispatch_async(dispatch_get_main_queue(), ^
{
[NSURLConnection sendAsynchronousRequest:request.signedURLRequest queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response1, NSData *data, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^
{
if (data)
{
[self loadData:data];
}
});
}];
});
}
}];
}
}

关于iphone - 如何使用 iOS 5 的 iOS TWRequest 获取 Twitter 用户详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17964388/

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