Tweet with media using REST API


#1

Hi,
I’m using REST API 1.1 , I would like send binary image along with status. May I know is that possible using twitter API.

If yes, Please provide me an example.

Regards,
Mikki


#2

There’s details on how media uploads work in the developer documentation. It might be an idea to find a library for your chosen platform / language which supports this, too.


#3

@andypiper, I am using a TIBCO designer tool. Below is my request, Please let me know were exactly im going wrong.

URI: https://api.twitter.com/1.1/media_data/upload.json

Input:

**<ns0:Parameters>
	<Query>
		<media>Binary Data</media>
	</Query>
	<Header/>
	<Body>
		<Form/>
		<Text/>
		<Binary/>
		<Multipart/>
	</Body>
</ns0:Parameters>

</ns0:ActivityInput>**

Output:
<ns0:RESTOutput xmlns:ns0 = “http://www.tibco.com/namespaces/tnt/plugins/json”>
401
{“errors”:[{“message”:“Could not authenticate you”,“code”:32}]}
</ns0:RESTOutput>

I even tried with media endpoint…but no luck.


#4

This looks like an authentication problem. I’m not familiar with the tool you’re using, how are you getting the OAuth tokens?


#5

@andypiper… I got from my twitter account and pasted manually. My guess is…may be cookies problem or call back url but not sure.

I could send status using ‘‘https://api.twitter.com/1.1/statuses/update.json’’ perfectly but could not upload images using ‘https://upload.twitter.com/1.1/media/upload.json’ .

I am confident that OAuth Details are right because as it is working to update status.


#7

@andypiper If possible, Can you please provide an example in SOAP UI.


#8

@andypiper Its working…fine…Problem was with Multipart

<?xml version="1.0" encoding="UTF-8"?>
<ns2:Parameters xmlns:pd="http://xmlns.tibco.com/bw/process/2003" xmlns:ns2="http://www.tibco.com/namespaces/tnt/plugins/json" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="http://www.tibco.com/namespaces/tnt/plugins/file" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Body>
        <Multipart>
            <name>
                <xsl:value-of select="'media'"/>
            </name>
            <content-type>
                <xsl:value-of select="'multipart/form-data'"/>
            </content-type>
            <content>
                <binary>
                    <xsl:value-of select="binaryContent"/>
                </binary>
            </content>
        </Multipart>
    </Body>
</ns2:Parameters>

#10

Aha that is great news! Glad you were able to resolve it, and thanks for sharing your knowledge here for others.