spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

How to post image to twitter with Twython?


Ok i had the same problem and I messed about with it and got it working.

I have put it into your code below (not tested it though)

from twython import Twython
import glob
import random

app_key = "XXX"
app_secret = "XXX"
oauth_token = "XXX"
oauth_token_secret = "XXX"
twitter = Twython(app_key, app_secret,
oauth_token, oauth_token_secret)

    def RandomImageTwitt(folder):
        #Takes the folder where your images are as
the input
        images = glob.glob(folder + "*")
        image_open =
open(images[random.randint(0,len(images))-1])
        #new code starts here 
        image_ids =
twitter.upload_media(media=image_open)
        twitter.update_status('hello this is a
status',image_ids['media_id'])


RandomImageTwitt("/home/XXX/.reddit-twitter-image/XXX/")

Categories : Python

Related to : How to post image to twitter with Twython?
Twython 403 forbidden error
You need to show more of your code so I can see what could be wrong. But my guess is that you maybe making the same error I did. To update your status you do not need to do this: twitter.verify_credentials() You can use the Access Key and secret from your twitter application to update your own account. But more code will help figure this out.

Categories : Twitter
Twython : cursor on statuses/get_user_timeline returns my tweets instead of screen_name passed
This problem of getting the tweets from the authenticated user happened to me before. The reason was that I was giving as argument an non-existent user. Make sure you don't confuse the name with the screen-name.

Categories : Misc
Twitter Sign In using LINQ to twitter
I think that the guy from the article didn't use ajax requests. The twitter oauth api doesn't support CORS.

Categories : C#
How to get name from twitter id with php
You want to use the users/lookup API call. In the above example, you would call: https://api.twitter.com/1.1/users/lookup.json?user_id=378176058,565040748 That will return an unordered list of all the users. You can parse it to find the names.

Categories : PHP
Change image on click, keep image and remove if other image is clicked
var sourceSwap = function () { var $this = $(this); if (!$this.hasClass('active')) { var newSource = $this.data('alt-src'); $this.data('alt-src', $this.attr('src')); $this.attr('src', newSource); } } var makeActive = function() { var $this = $(this); // bring the active back (if any) to the first state if($('img.active').length) { var

Categories : Javascript
Recently Add
Adding json to new Django database
document clustering in python
Only read the last character in a .txt file
Is it possible to redirect to different domain retaining the trailing endpoint, from a route?
Python NameError: not defined
Numpy array loop
Turning off Tick Marks in Bokeh
Python: Number and operator concatenation not working (Euler's Method)
Python: Twitter API tweets/search: Flatten nested dictionary to columns
Python 2.7 cmd autocomplete readline buffers seem stale
Memory usage/efficiency for pandas dataframe versus lists versus tuples, etc.
How can i use multiple lists as arguments in a function and receive them differently?
PyQt - setText method of QTableWidget gets AttributeError
Matplotlib - get value of autoscale
Backwards axes in numpy.delete
Twilio - How to determine the length of a conference call?
Counting string using for loop
Automating creation of class instances in python for an undetermined amount of instances
Printing 2D-array in a grid
Load PreComputed Vectors Gensim
IPython _repr_html_
Reversing a number using recursion
Is there a configuration under which a numpy operation will work on more than a single core/thread?
Is there a better way to write this if-statement?
Python: Effective reading from a file using csv module
Django/Python: CSV for-in loop overriding first row each time through
How to read the pickled igraph graph object from old version by new version igraph
Tornado WebSocket with Django ORM with shared session
trying to plot contours of bivariate normal, won't work with a correlation term
Python split users input
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.