image uploaded and we got the media_key
when I try to create media card using this media key
I got this error INVALID_MEDIA
here is the result for the media upload
(
[media_id] => 1288085380328194048
[media_id_string] => 1288085380328194048
[media_key] => 3_1288085380328194048
[size] => 141033
[expires_after_secs] => 86400
[image] => stdClass Object
(
[image_type] => image/jpeg
[w] => 800
[h] => 800
)

)

and here is the error when I try to create card using this media_key
(
[0] => stdClass Object
(
[code] => INVALID_MEDIA
[message] => Invalid media key: MediaKey(TweetImage,1288085380328194048)
)

)

One common error is not sharing the asset with the Ads Account that will be using the image as described in this tutorial. Did the Init request include the additional_owners for a user that will be creating the card?

If this doesn’t resolve this, could you provide the API requests for the upload and Card endpoints?

1 Like

we using GitHub - hborras/twitter-php-ads-sdk: A Twitter supported and maintained Ads API SDK for PHP.

and here is our code

                $account = new Account($account_id);
                $account->read();

                $fundingInstruments = $account->getFundingInstruments();
                $fundingInstrument = $fundingInstruments->getCollection()[0];

                $media = $api->upload(['media' => 'j800.jpg', 'media_type' => 'image/jpg'], true);

                $mediaid = $media->media_key;
                $websiteCard = new WebsiteCard();
                $websiteCard->setImageMediaId($media->media_id);
                $websiteCard->setImageMediaKey($mediaid);
                $websiteCard->setName('cardnametest');
                $websiteCard->setWebsiteTitle('cardtitletest');
                $websiteCard->setWebsiteUrl('http://*************/campaign/images/list');
                $websiteCard->save();

“The additional_owners field is set to the user ID of the @xxx account”

We don’t have a numerical user ID, only the username

When trying to get it via API we get stuck as our app is approved for Ads but not for Users

How can we get the User ID for each of our username/account?

Your application can obtain this the FULL promotable user from the GET promotable_users endpoint.

{
  "request": {
    "params": {
      "promotable_user_ids": [
        "l310s"
      ],
      "account_id": "18ce54d4x5t"
    }
  },
  "next_cursor": null,
  "data": [
    {
      "user_id": "756201191646691328",
      "id": "l310s",
      "created_at": "2016-07-21T22:42:09Z",
      "updated_at": "2016-07-21T22:42:09Z",
      "deleted": false,
      "promotable_user_type": "FULL"
    }
  ]
}

still have the same issue even after using ‘additional_owners’
here it the init request to upload the media file

    [command] => INIT
    [media_type] => image/jpg
    [media_category] => tweet_image
    [total_bytes] => 157802
    [additional_owners] => 1222914855361024000

here is the response for upload

    [media_id] => 1290198647448252416
    [media_id_string] => 1290198647448252416
    [media_key] => 3_1290198647448252416
    [size] => 141033
    [expires_after_secs] => 86400
    [image] => stdClass Object
        (
            [image_type] => image/jpeg
            [w] => 800
            [h] => 800
        )

and then when we try to create websitecard we got this response

    [0] => stdClass Object
        (
            [code] => INVALID_MEDIA
            [message] => Invalid media key: MediaKey(TweetImage,1290198647448252416)
        )

we have only 1 user id under the account, and it’s the same account, user that we use to upload and create the card

It looks like the script needs to add the asset to the Media Library prior to creating the Website Card. Use the POST media_library endpoint with the media_key=3_1290198647448252416.