gpt4 book ai didi

ios - Twitter SLRequest 身份验证错误

转载 作者:行者123 更新时间:2023-11-30 13:35:24 26 4
gpt4 key购买 nike

我一直在尝试利用内置的 iOS 帐户和 Twitter 框架检索 Twitter 用户数据。

我已成功访问手机上的用户帐户。但是,当向 twitter 发出 SLRequest 时,我收到未经身份验证的错误。我的印象是,将用户 ACCount 分配给 twitter SLRequest.account 满足了必要的 OAuth 部分。

代码来 self 设置的测试项目

非常感谢任何反馈!

var accountArray = AnyObject var account = ACAccount()

override func viewDidLoad() {
super.viewDidLoad()

let accountStore: ACAccountStore = ACAccountStore()
let twitterAccountType: ACAccountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierTwitter)
let url = NSURL(string: "https://api.twitter.com/1.1/users/show.json")
let params: NSDictionary = ["field": "user_id, screen_name"]

accountStore.requestAccessToAccountsWithType(twitterAccountType, options: nil, completion: { (success, error) -> Void in

if success {
let account = accountStore.accountsWithAccountType(twitterAccountType)
if let userAccount = account.first as? ACAccount {
self.accountsArray.append(userAccount)

let twitterRequest = SLRequest(forServiceType: SLServiceTypeTwitter, requestMethod: SLRequestMethod.GET, URL: url, parameters: params as [NSObject : AnyObject])

根据我的发现,我认为下面的行涵盖了 twitter api 版本 1.1 的 OAuth 要求

      twitterRequest.account = userAccount
twitterRequest.performRequestWithHandler({ (responseData : NSData?, urlResponse : NSHTTPURLResponse?, error : NSError?) -> Void in

print("data : \(responseData)")
if let response = responseData {
var dict = NSDictionary()
do {
dict = try! NSJSONSerialization.JSONObjectWithData(response, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
}
print(dict)
} else if error != nil {
print("Error : \(error)")
}
})
}
} else if (error != nil) {
print("nooope")
}
})

}
}

从字典返回的内容:

{
errors = (
{
code = 50;
message = "User not found.";
}
);
}

最佳答案

参数字典应该是:

["screen_name": "username"]

关于ios - Twitter SLRequest 身份验证错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36133846/

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