我想要使用下面的代碼從給定的用戶名請求和解析20條推文。儘管在NSLog中,我得到的只是錯誤的身份驗證錯誤。有人可以幫助我修正我的代碼並指出我朝着正確的方向嗎?要求使用Twitter API的用戶名的Twitter時間線1.1
在此先感謝!您被授予訪問權限之前
- (void)getTweets:(NSString *)username {
NSURL *getTimeline = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"];
NSString *paraString = [NSString stringWithFormat:@"%@", username];
NSDictionary *parameters = [NSDictionary dictionaryWithObject:paraString forKey:@"username"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:getTimeline parameters:parameters];
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
if (accounts.count > 0)
{
for (ACAccount *twitterAccount in accounts) {
[request setAccount:twitterAccount];
}
}
[self getTweets:@"@IsaRanjha"];
}
}
];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (!error)
{
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSLog(@"%@", json);
}
else
{
//Deal with error
}
}];}
謝謝,但仍然得到錯誤認證錯誤。 –
它適用於我/我的用戶名。嘗試調用[self getTweets:@「IsaRanjha」](沒有第二個@)。確保這是您的實際用戶名。 – Sean
當我回家時,我會嘗試。它在日誌中究竟報告了什麼,只有最後的50條推文是正確的?我將如何將這個信息加載到UITableView中?因爲我所知道的是用數組加載UITableView,你能幫我嗎?謝謝。 –