Need help making 1.1/post/statuses/update_with_media in python


#1

Hi, I am making a python project with twitter API, I’ve already posted a tweet, but when I try to post a photo I get this error: “Missing or invalid url parameter.”

I think that the issue is in the media parameter, need some help with that.

this is my code:

#!/usr/bin/python
# -*- encoding: utf-8 -*-
import oauth2 as oauth
import json
import urllib
import sys




CONSUMER_KEY = "x"
CONSUMER_SECRET = "x"
ACCESS_KEY = "x-x"
ACCESS_SECRET = "x"
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
access_token = oauth.Token(key=ACCESS_KEY, secret=ACCESS_SECRET)
client = oauth.Client(consumer, access_token)

def search():
	term=sys.argv[2]
	count=sys.argv[3]
	params = {'count': count,'q':term,'lang':'es'}
	twurl = "https://api.twitter.com/1.1/search/tweets.json?"+urllib.urlencode(params)
	response, data = client.request(twurl)      
	statuses = json.loads(data)
	print data
	for status in statuses['statuses']:
		print status['text']

def post():
	message=sys.argv[2]
	media=["twit.gif"]
	params = {'status':message,'media[]':media}	
	twurl = "https://api.twitter.com/1.1/statuses/update_with_media.json?"+urllib.urlencode(params)
	try:	
		response, data = client.request(twurl,"POST")
		text = json.loads(data)
	#print response
	#print data
		statuses=json.loads(data)
	#print text['id']
	except Exception:
		print("ERROR: no se pudo twittear")	
	if 'id' in text:
		print ("Enviado con exito")
	else:
		for tex in text['errors']:
			print "Error: %s"%tex['message']

def get():

	user=sys.argv[2]

	N=sys.argv[3]
	params={'screen_name':user,'count':N}
	twurl = "https://api.twitter.com/1.1/statuses/user_timeline.json?"+urllib.urlencode(params)
	response, data = client.request(twurl)
	#print response
	text = json.loads(data)
	print data
	for tex in text:
		print tex['text']

if sys.argv[1]=='search':
	search()

if sys.argv[1]=='post':
	post()

if sys.argv[1]=='get':
	get()