我尝试使用适用于iOS的TwitterKit API提取列表成员。据我了解,这样做可以让我做客人认证"绕过了我个人消费者和消费者密钥的需要。
以下代码尝试使用this REST endpoint
获取列表成员let client = TWTRAPIClient()
let endpoint = "https://api.twitter.com/1.1/lists/members.json"
let params = ["owner_screen_name" : "palafo", "slug" : "breakingnews"]
var clientError : NSError?
let request = client.URLRequestWithMethod("GET", URL: endpoint, parameters: params, error: &clientError)
client.sendTwitterRequest(request) { (response, data, connectionError) -> Void in
if connectionError != nil {
print("Error: \(connectionError)")
}
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: [])
print("json: \(json)")
} catch let jsonError as NSError {
print("json error: \(jsonError.localizedDescription)")
}
}
运行它会给我这个错误:
Error Domain=TwitterAPIErrorDomain Code=220 "Request failed: forbidden (403)" UserInfo={NSLocalizedFailureReason=Twitter API error : Your credentials do not allow access to this resource (code 220), TWTRNetworkingStatusCode=403, NSErrorFailingURLKey=https://api.twitter.com/1.1/lists/members.json?owner_screen_name=palafo&slug=breakingnews, NSLocalizedDescription=Request failed: forbidden (403)})
如果我更改endpoint
而不是使用this other REST endpoint获取该列表中的状态,我会收到正确的JSON响应。
let endpoint = "https://api.twitter.com/1.1/lists/statuses.json"
这是否意味着Fabric的访客身份验证不允许我获取列表成员?
答案 0 :(得分:7)
我使用clientWithUserId解决了我的问题,而不是仅使用init初始化。
NSString *userID = [Twitter sharedInstance].sessionStore.session.userID;
TWTRAPIClient *client = [[TWTRAPIClient alloc] initWithUserID:userID];