Page 1 of 1

Post image snapshot to TwitPic web service....

Posted: Sun Jan 18, 2009 2:28 am
by jpatten
Hi All...

I'm trying to post a card snapshot to the "Web 2.0" twitpic web service.

Their API for post data is:
METHOD: http://twitpic.com/api/uploadAndPost

Use this method to upload an image to TwitPic and to send it as a status update to Twitter.

Fields to post in
(post data should be formatted as multipart/form-data):
- media (required) - Binary image data
- username (required) - Twitter username
- password (required) - Twitter password
- message (optional) - Message to post to twitter. The URL of the image is automatically added.

Sample response:

<?xml version="1.0" encoding="UTF-8"?>
<rsp status="ok">
<statusid>1111</statusid>
<userid>11111</userid>
<mediaid>abc123</mediaid>
<mediaurl>http://twitpic.com/abc123</mediaurl>
</rsp>
I have never attempted to do this from Rev, so I don't have a framework to go on. I attempted the following script but I get an error from TwitPic saying the password and username is incorrect.

Here's what I tried:

on mouseUp
import snapshot
set cursor to 1
set the imageData of last image to thebinarydata
put thebinaryData into tmedia
put URLEncode("media=tmedia&username=TwitterUsername&password=twitterPassword&message=test from my rev project") into theDataToSend
post theDataToSend to URL "http://twitpic.com/api/uploadAndPost"
if the result is empty then
answer it
else
answer the result
end if
end mouseUp


I get the following error from TwitPic:

<?xml version="1.0" encoding="UTF-8"?>
<rsp stat="fail">
<err code="1001" msg="Invalid twitter username or password" />
</rsp>

I have a hunch the binary data of the snapshot is not correct either...


Has anyone done something like this and has a working example?

Thank you!

Posted: Sun Jan 18, 2009 1:51 pm
by Mark Smith
You need to create a multipart/form type post.

I'm not well up on this, but see "libUrlMultipartFormData" and "libUrlMultipartFormAddPart" in the docs...

Best,

Mark