bear / python-twitter

A Python wrapper around the Twitter API.
Apache License 2.0
3.41k stars 957 forks source link

twitter.error.TwitterError: {'code': 44, 'message': 'attachment_url parameter is invalid.'}] #597

Closed acupoftee closed 5 years ago

acupoftee commented 5 years ago

I am trying to use PostUpdate(text, attachment_url)method in order to share a quoted tweet by using Twitter's shortened URL https://t.co/ followed by a status ID. Here's my code below:

api.PostUpdate(hashtags, attachment_url="https://t.co/AbcDe13gg")

Here is the traceback below:

Traceback (most recent call last):
  File "bot.py", line 83, in <module>
    send_quoted_tweet(new_tweet)
  File "sombra_bugs.py", line 65, in send_quoted_tweet
    api.PostUpdate(hashtags, attachment_url="https:\/\/t.co\/FzTADy3Zgg")
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twitter/api.py", line 1177, in PostUpdate
    data = self._ParseAndCheckTwitter(resp.content.decode('utf-8'))
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twitter/api.py", line 4908, in _ParseAndCheckTwitter
    self._CheckForTwitterError(data)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/twitter/api.py", line 4928, in _CheckForTwitterError
    raise TwitterError(data['errors'])
twitter.error.TwitterError: [{'code': 44, 'message': 'attachment_url parameter is invalid.'}]

I've also tried using escape characters in case that was the issue and it still raised the error. What is considered a bad URL? Thank you for your time

jeremylow commented 5 years ago

If I’m reading the documentation correctly, you should attach the non-shortened status url as attachment_url:

In order for a URL to not be counted in the body of the Tweet, a new attachment_url parameter will be available on statuses/update to allow a client to attach it to the Tweet without explicitly adding it to the Tweet text. This URL must be a Tweet permalink, or DM deep link. Arbitrary, non-Twitter URLs should remain in the Tweet text and will count against the Tweet text length limit. URLs passed to the attachment_url parameter not matching either a Tweet permalink or DM deep link will fail at Tweet creation and cause an exception.

See here https://developer.twitter.com/en/docs/tweets/tweet-updates

acupoftee commented 5 years ago

Thank you @jeremylow. The full status URL worked.

hsmatis commented 5 years ago

I am getting the same error and I used the line
url= "https://www.google.com" twitter.error.TwitterError: [{'code': 44, 'message': 'attachment_url parameter is invalid.'}] I have tried many other urls and they all fail with the save error. Can anyone give me a url that actually works?