Flickr 照片上传不适用于 OAtuth1Swift postImage 方法
Flickr photo upload does not work with OAtuth1Swift postImage Method
我目前面临的问题是,在 OAuth1 流程之后,当我真正想要发送图像时,flickrapi 响应:未指定照片。 :
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
<err code="2" msg="No photo specified" />
</rsp>
我在 XCode 10、Swift 4 上使用 ios 的 OAtuthSwift 框架来完成此任务。
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
我目前面临的问题是,在 OAuth1 流程之后,当我真正想要发送图像时,flickrapi 响应:未指定照片。 :
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
<err code="2" msg="No photo specified" />
</rsp>
我在 XCode 10、Swift 4 上使用 ios 的 OAtuthSwift 框架来完成此任务。
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