facebook / facebook-ruby-business-sdk

Ruby SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
209 stars 160 forks source link

read after write not working for adimages? #50

Closed joephayes closed 4 years ago

joephayes commented 6 years ago

No matter what I put in fields I always get back image hash and url

I modified the example image_upload.rb file as follows:

images = ad_account.adimages.create({
  logo1: File.open(File.expand_path("../logo1.jpg", __FILE__)),
  logo2: File.open(File.expand_path("../logo2.png", __FILE__)),
  fields: ['name','hash']
})

and the object I get back contains hash and url attributes.

#<FacebookAds::AdImage {:hash=>"XXXXXXXXXX", :url=>"https://scontent.xx.fbcdn.net/v/t45.1600-4/XXXXXXXXXX"}>

Is read after write supported for ad images?

joaquincorrales commented 6 years ago

I don't think so. What are you trying to accomplish?

Also, do you know if there's anyway for us to catch error codes? The exception for a limited app or an invalid access token can only be caught as a string with a begin rescue.

joephayes commented 6 years ago

I'm trying to upload images and I'd like to get back the hashes and the names of the images.

On Tue, Jul 17, 2018 at 7:28 PM Joaquin Corrales notifications@github.com wrote:

I don't think so. What are you trying to accomplish?

Also, do you know if there's anyway for us to catch error codes? The exception for a limited app or an invalid access token can only be caught as a string with a begin rescue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/facebook/facebook-ruby-business-sdk/issues/50#issuecomment-405759982, or mute the thread https://github.com/notifications/unsubscribe-auth/ACQPPhKVcvJwnSvKRjBHSXMu1LA-n-Oyks5uHnMbgaJpZM4VTrjr .

joaquincorrales commented 6 years ago

The name of the image is assigned on upload. Use that name and the hashes that come back

joephayes commented 6 years ago

Also, do you know if there's anyway for us to catch error codes? The exception for a limited app or an invalid access token can only be caught as a string with a begin rescue.

I don't.

joephayes commented 6 years ago

One thing I did find is that we can get to the last API response:

...
results = ad_account.adimages.create(files_to_upload)

last_response = ad_account.last_api_response

puts last_response

returns something like this:

#<FacebookAds::APIResponse:0x0000XXXXXXX @status_code=200,
@headers={"access-control-allow-origin"=>"*", "pragma"=>"no-cache", "cache-control"=>"private, no-cache, no-store, must-revalidate", "facebook-api-version"=>"v3.0", "expires"=>"Sat, 01 Jan 2000 00:00:00 GMT", "x-fb-rev"=>"4114154", "content-type"=>"application/json; charset=UTF-8", "x-fb-trace-id"=>"XXXXXXX", "strict-transport-security"=>"max-age=15552000; preload", "vary"=>"Accept-Encoding", "x-fb-debug"=>"XXXXXXX", "date"=>"Wed, 18 Jul 2018 14:04:01 GMT", "connection"=>"close", "content-length"=>"425"},
@body="{\"images\":{\"elephant.png\":{\"hash\":\"XXXXX\",\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t45.1600-4\\/XXXXX\"},\"nodejs-logo.png\":{\"hash\":\"XXXXX\",\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t45.1600-4\\/XXXXX\"},\"MongoDB-Logo.png\":{\"hash\":\"XXXXXX\",\"url\":\"https:\\/\\/scontent.xx.fbcdn.net\\/v\\/t45.1600-4\\/XXXXXXXX\"}}}">

That would allow you to check for status codes, etc. I was able to grab both the name and hash from the response, so that resolved my immediate issue.

joephayes commented 6 years ago

Could someone from Facebook weigh in here though? Are there plans to support read after write when creating ad images? Or is it already supported and I did something wrong in my code?

alanho commented 6 years ago

are you trying to get the name of the image from read-after-write? read-after-write is supported in /adimages it's just name of the images will be the key of the hash returned. and the sdk do not extract the key and put it in AdImage object currently

joephayes commented 6 years ago

@alanho - Thanks for the response and that it what I'm doing. I did realize the name comes back in the response and so I'm using the last_api_response property of the ad account to get at them (see my comment above - https://github.com/facebook/facebook-ruby-business-sdk/issues/50#issuecomment-405943862)

If this is the case, then what is the use of the fields key when you create ad images? See the example image upload file - https://github.com/facebook/facebook-ruby-business-sdk/blob/master/examples/image_upload.rb

stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.