我目前面临的问题是,在OAuth1进程之后,当我真正想发送图像时,flickrapi的响应是:没有指定照片。:
<?xml version="1.0" encoding="utf-8" ?><rsp stat="fail"> <err code="2" msg="No photo specified" /></rsp>
我在XCode 10上使用ios的oatushswift框架,在这个任务中使用Swift 4。

oAuthSwift = OAuth1Swift(consumerKey: flickr.apiKey,
                        consumerSecret: flickr.apiSecret,
                        requestTokenUrl: "https://www.flickr.com/services/oauth/request_token",
                        authorizeUrl: "https://www.flickr.com/services/oauth/authorize",
                        accessTokenUrl: "https://www.flickr.com/services/oauth/access_token")

if oAuthSwift != nil {
   oAuthSwift?.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oAuthSwift!)

   guard let rwURL = URL(string: "iflickr://oauth-callback/iflickr") else {
       return
   }
   let handle = oAuthSwift!.authorize( withCallbackURL: rwURL) { [unowned self] result in
       switch result {
       case .success(let (credential, response, parameters)):
           print(credential.oauthToken)
           print(credential.oauthTokenSecret)

           guard let img = self.image?.jpegData(compressionQuality: 0.0) else {
               print ("cant convert image")
               return
           }
           var params = parameters

// Until Here seems everything fine

           self.oAuthSwift!.client.postImage(flickr.uploadEndpoint, parameters: params, image: img) { upResult in
               switch upResult {
               case .failure(let error):
                   print (error)
               case .success(let response):
                   let respData = response.data
                   if let string = response.string {
                       print ("\nRESULT:\n      - \(string)\n")
                      // Here it prints the above described `No Photo Specified`
                   }
               }
           }
       case .failure(let error):
           print(error.localizedDescription)
       }
   }
}

我还尝试自己执行请求,只获取OAuth进程(参数)提供的字典的值,但随后它会说:没有提供任何令牌。。
有人能帮忙吗?

最佳答案

正如@Clemens Brockschmidt提到的,图像参数不正确。OAuthSwift提供了标准的“media”作为参数名,flickr上载API不接受该名称。
认识到这一点后,我将参数名从“media”改为“photo”。
代码在中
OAuthSwift/Sources/OAuthSwiftClient.swift:multiPartRequest(),第125行
https://github.com/OAuthSwift/OAuthSwift/blob/b8941a23d1584ba17426c312bb957de355341f4a/Sources/OAuthSwiftClient.swift#L125

关于swift - Flickr照片上传不适用于OAtuth1Swift postImage方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57727199/

10-11 03:00