1
我需要獲取公共賬戶的推文供稿。我可以用下面的代碼,讓我自己的Twitter飼料:iOS:獲取公共賬戶的推特供稿
-(void) testTwitter {
{
ACAccountStore *accountStore = [[ACAccountStore alloc]init];
if (accountStore != nil)
{
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
if (accountType != nil)
{
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted)
{
//Succesful Access
NSArray *twitterAccounts = [accountStore accountsWithAccountType:accountType];
if (twitterAccounts != nil)
{
ACAccount *currentAccount = [twitterAccounts objectAtIndex:0];
if (currentAccount != nil)
{
NSString *paraString = [NSString stringWithFormat:@"qlx_corp"];
NSDictionary *parameters = [NSDictionary dictionaryWithObject:paraString forKey:@"username"];
NSString *requestString = @"https://api.twitter.com/1.1/statuses/user_timeline.json";
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:requestString] parameters:parameters];
[request setAccount:currentAccount];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ((error == nil) && ([urlResponse statusCode] == 200))
{
NSArray *twitterFeed = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:nil];
NSDictionary *firstPost = [twitterFeed objectAtIndex:0];
NSLog(@"firstPost = %@", [firstPost description]);
}
else {
NSLog(@"error: %@",error);
}
}];
}
}
}
else
{
//Access Denied
NSLog(@"access denied");
}
}];
}
}
}
}
但是,當我替換下面的代碼用於獲取帳戶以外我自己,我得到這個錯誤:
碼= 215;
message =「Bad Authentication data。」;
這是我代替一個成功的接入代碼(在發佈代碼中的註釋說明):
NSURL* url = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"];
NSDictionary* params = @{@"count" : @"10", @"screen_name" : @"qlx_corp"};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:url parameters:params];
[request performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error) {
if (!error) {
NSError *jsonError;
NSArray *responseJSON = [NSJSONSerialization
JSONObjectWithData:responseData
options:NSJSONReadingAllowFragments
error:&jsonError];
NSLog(@"response json: %@",responseJSON);
// Show the content of the responseJSON in a view.
}
}];
什麼我做錯了,我收到此錯誤信息,而不是公共Twitter的飼料我正在請求。我的應用程序要求獲得Twitter使用許可,並已獲得批准,那麼可能是什麼問題?
您是否試過這種方法:http://stackoverflow.com/questions/28498038/fetching-twitter-public-feeds-as-json/28663071#28663071? –
嗯,我沒有使用Twitter API,我正在使用Apple的Social框架。所以我試圖避免使用不同的技術,但如果我找不到解決方案,那麼這將是一個尋找替代品的好地方。謝謝! –