xdevplatform/twitter-ruby-ads-sdk

Error when calling save on promoted tweet object

Closed this issue · 2 comments

Whenever I try save a PromotedTweed instance I get the following error:

TypeError: no implicit conversion of Symbol into Integer

After some debugging, realised that the issue is that the "data" key in the response body from the API is empty. I was expecting that field to contain the information of the new promoted tweet that was created and so was the gem. Please find below the response I'm getting, everything indicates that the promoted tweet is created successfully but no information about it is returned.

pry(#<TwitterAds::Request>)> response
=> #<Net::HTTPCreated 201 Created readbody=true>

pry(#<TwitterAds::Request>)> response.body
=> "{\"data_type\":\"promoted_tweet\",\"data\":[],\"request\":{\"params\":{\"line_item_id\":\"3ebl7\",\"account_id\":\"18ce53uoyi3\"}},\"total_count\":0}"

Link to Promoted Tweets creation docs

UPDATE
Looks like the API is expecting a tweet_ids param in the POST request, but the gem only provides the tweet_id property for the PromotedTweet class

https://github.com/twitterdev/twitter-ruby-ads-sdk/blob/master/lib/twitter-ads/creative/promoted_tweet.rb#L22

UPDATE 2
After trying using twurl the call was successful by passing the tweet_ids parameter

twurl -X POST -H ads-api.twitter.com '/0/accounts/18ce53uoyi3/promoted_tweets.json?line_item_id=3f3w2&tweet_ids=656502909367132161'
{"data_type":"promoted_tweet","data":[{"line_item_id":"3f3w2","display_properties":[],"id":"ci7vf","paused":false,"created_at":"2015-10-20T16:29:33Z","updated_at":"2015-10-20T16:29:33Z","approval_status":"ACCEPTED","tweet_id":"656502909367132161","deleted":false}],"request":{"params":{"line_item_id":"3f3w2","tweet_ids":[656502909367132161],"account_id":"18ce53uoyi3"}},"total_count":1}%

Thanks for reporting @GonzoGhanem. It looks like this is the result of a series of bugs / inconsistencies both API side and in the SDK:

  1. API is inconsistent with other similar APIs (eg. promoted account) in how it receives identifiers. The SDK won't handle this without a save method override since this object breaks the mold a bit.
  2. API responses for successful calls to this endpoint are inconsistent. This endpoint is very old and this design is from the early days of the Ads API. This endpoint is trying to be a batch endpoint when it shouldn't. We should roll batch promoted tweets in the batch API standard rather than keep this "odd duck" behavior in this endpoint around.
  3. Validation is not happening correctly, response body is empty on missing param tweet_ids.

The first issue is an SDK issue and I resolved it in 0.2.4 although the resolution introduced #41. I'll have a fix out for that shortly. The other two issues are server-side on twitter's end which I'm pursuing as well.

Thanks for the turn around @brandonblack I've also submitted a PR with some fixes that we did to bypass a few errors, like being able to edit campaigns i.e. Please let us know what do you think about, we are happy to contribute if needed