Problem:
TwitPic has a restricted crossdomain.xml file preventing your Flash web applications from posting directly to the service.
Solution:
Create a simple PHP script to proxy the request through a server that you do have access to!
Here is the code:
<?php $post_tweet_url='http://twitpic.com/api/uploadAndPost'; $file=$_FILES['media']; $postfields = array(); $postfields['username'] = $_POST['username']; $postfields['password'] = $_POST['password']; $postfields['message'] = $_POST['message']; $postfields['media'] = "@$file[tmp_name]"; $curl = curl_init(); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, $post_tweet_url); curl_setopt($curl, CURLOPT_POST, 3); curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); $result = curl_exec($curl); curl_close($curl); header ("content-type: text/xml"); echo $result ; ?>
Just create a PHP file with the contents above and replace the post URL from my previous example with the path to this script.
Enjoy!
Great Chris! It works fine!!!
Hi,
You can actually use the twitpic api from flash/flex, for an example you can check this project
http://github.com/julien/twup/tree/master/
Cheers
Thanks !!!
Thanks for the sample code Julien. The PHP is only required when building a web application. Adobe AIR uses local host for connection which doesn’t require a crossdomain.xml file. The policy file on TwitPic does require some form of server side code to submit.
Thanks Chris