Hi! I’m trying to create a new campaign for one of my accounts and I’m succeeding, but when I try to create tweets for that campaign I receive this error. (I have the permissions for create promoted tweet in the account…)

NotAuthorized object at ######## code=401 details=[{u’message’: u’User ######## is not authorized to create tweets for user id #####‘, u’code’: u’UNAUTHORIZED_ACCESS’}]>

Does someone knows why?!

@nicomilie: Thanks for the question. Please make sure you are using the as_user_id parameter.

Users granted an Ads Manager role via the Twitter UI at ads.twitter.com can create Tweets on behalf of the advertiser using the as_user_id parameter. For more information on Ads Manager permissions, see Obtaining Ads Access.

More information here: POST accounts/:account_id/tweet.

Thanks! Where can I get my ‘as_user_id’ param?? i need it only for creating tweets or something else?

thanks again

@nicomilie: Are you asking where to find this value? If so, you can use the GET users/show endpoint. Look for the id_str attribute. See the following example:

$ twurl -H api.twitter.com "/1.1/users/show.json?screen_name=twitterdev" | jq
{
  "id": 2244994945,
  "id_str": "2244994945",
  "name": "TwitterDev",
  "screen_name": "TwitterDev",
  "location": "Internet",
  "profile_location": null,
  "description": "Developer and Platform Relations @Twitter. We are developer advocates. We can't answer all your questions, but we listen to all of them!",
  "url": "https://t.co/66w26cua1O",
  "entities": {
    "url": {
      "urls": [
        {
          "url": "https://t.co/66w26cua1O",
          "expanded_url": "https://dev.twitter.com/",
          "display_url": "dev.twitter.com",
          "indices": [
            0,
            23
          ]
        }
      ]
    },
    "description": {
      "urls": []
    }
  },
  "protected": false,
  "followers_count": 437141,
  "friends_count": 1535,
  "listed_count": 1045,
  "created_at": "Sat Dec 14 04:35:55 +0000 2013",
  "favourites_count": 1887,
  "utc_offset": -25200,
  "time_zone": "Pacific Time (US & Canada)",
  "geo_enabled": true,
  "verified": true,
  "statuses_count": 2796,
  "lang": "en",
  "status": ...,
  "contributors_enabled": false,
  "is_translator": false,
  "is_translation_enabled": false,
  "profile_background_color": "FFFFFF",
  "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
  "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
  "profile_background_tile": false,
  "profile_image_url": "http://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png",
  "profile_image_url_https": "https://pbs.twimg.com/profile_images/530814764687949824/npQQVkq8_normal.png",
  "profile_banner_url": "https://pbs.twimg.com/profile_banners/2244994945/1396995246",
  "profile_link_color": "0084B4",
  "profile_sidebar_border_color": "FFFFFF",
  "profile_sidebar_fill_color": "DDEEF6",
  "profile_text_color": "333333",
  "profile_use_background_image": false,
  "has_extended_profile": false,
  "default_profile": false,
  "default_profile_image": false,
  "following": true,
  "follow_request_sent": false,
  "notifications": false,
  "translator_type": "regular"
}

You need to use this value with the as_user_id parameter if creating Tweets on behalf of another user (as long as the user you’re trying to Tweet as has given you permission to do so).

This post might also help.