将我的应用中的照片上传到用户的Twitter帐户工作正常,突然间我收到了这个错误:
错误域= TwitterAPIErrorDomain代码= 32"请求失败:未授权(401)" UserInfo = {NSErrorFailingURLKey = https://upload.twitter.com/1.1/media/upload.json,NSLocalizedDescription =请求失败:未授权(401),NSLocalizedFailureReason = Twitter API错误:无法验证您。 (代码32)}
以下是我开始推特会议的方式:
Twitter.sharedInstance().logInWithCompletion({ (session, error) -> Void in
})
接下来是我如何将媒体上传到Twitter,错误来自sendtwitterRequest方法:
let store = Twitter.sharedInstance().sessionStore
if let userid = store.session()?.userID {
let client = TWTRAPIClient(userID: userid) //we have this from logInWithCompletion() in the previousVC
let imageData = UIImagePNGRepresentation(self.cardView.takeSnapshot())
let uploadParams = ["media" : imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)]
//TODO: Handle error properly (do / catch?)
let uploadRequest = client.URLRequestWithMethod(kTwitterPOSTmethod, URL: kTwitterUploadURL, parameters: uploadParams, error: nil)
//First we upload the image via a request
client.sendTwitterRequest(uploadRequest, completion: { (response, uploadResultData, error) -> Void in
..使用sendTwitterRequest方法返回上面引用的错误。
有什么想法吗?我更新了TwitterKit SDK,它仍然给了我"无法验证你"错误。
答案 0 :(得分:0)
他们已经发布了包含公共上传功能的TwitterKit 2.0版本。