我一直在寻找最近2天的解决方案,这也是我在这里的第一个问题所以请耐心等待。
我正在尝试使用上传qbo api上传jpg图片,但不断收到错误代码500并显示消息Unsupported OperationOperation不支持使用内容类型。
我的要求是:
@client = Signet::OAuth1::Client.new(
:temporary_credential_uri => "https://oauth.intuit.com/oauth/v1/get_request_token",
:authorization_uri => "https://appcenter.intuit.com/Connect/Begin",
:token_credential_uri => "https://oauth.intuit.com/oauth/v1/get_access_token",
:client_credential_key => App.find_by_name('quickbooks').clientid,
:client_credential_secret => App.find_by_name('quickbooks').clientsecret
)
@client.token_credential_key = quickbooks.accesstoken
@client.token_credential_secret = quickbooks.refreshtoken
realmid =quickbooks.uid
url = Rails.env.eql?("development")? "sandbox-quickbooks.api.intuit.com" : "quickbooks.api.intuit.com"
object = {
"AttachableRef": [
{
"EntityRef": {
"type": "Invoice",
"value": "95"
}
}
],
"FileName": params[:file].original_filename,
"ContentType": "image/jpg"
}
original_request = [
'Post',
"https://#{url}/v3/company/#{realmid}/upload",
[
['Content-Type', 'application/json'],
['boundary', '0be01941e049'],
],
[object.to_json]
]
response = @client.fetch_protected_resource(:request => original_request)
作出回应:
<Error code=\"500\"><Message>Unsupported Operation</Message><Detail>Operation Cannot consume content type is not supported.</Detail></Error></Fault></IntuitResponse>"
任何帮助都将不胜感激。感谢
:修改
使用quickbook-ruby gem ----&#39; github.com/ruckus/quickbooks-ruby#uploading-an-actual-file'
::QB_OAUTH_CONSUMER = OAuth::Consumer.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_url => "https://appcenter.intuit.com/Connect/Begin",
:access_token_path => "/oauth/v1/get_access_token"
})
meta = Quickbooks::Model::Attachable.new
meta.file_name = "monkey.jpg"
meta.note = "A note"
meta.content_type = "image/jpg"
entity = Quickbooks::Model::BaseReference.new(123, type: 'Transfer')
meta.attachable_ref = Quickbooks::Model::AttachableRef.new(entity)
doc_path = 'Add file path'
upload_service = Quickbooks::Service::Upload.new(:realm_id=> '123XXX', :access_token=> 'QTYXXXXX')
result = upload_service.upload(doc_path, "image/jpeg")
我正面临一个错误 NoMethodError:未定义的方法`post_with_multipart&#39; for&#34; erXXXXXXXXXXXXXXXX6&#34;:String
即使我在我的代码中没有使用任何名为post_with_multipart的方法,这也是我在尝试上传图片时得到回应的内容 result = upload_service.upload(doc_path,&#34; image / jpeg&#34;)
答案 0 :(得分:0)
所以,如果有人在这里寻找解决方案,这就是我修复它的方法。 所以我总是做错了是我没有通过OAuth传递访问令牌。
token = OAuth::AccessToken.new($qb, oauth_token, oauth_secret)