Jump to content

Uploading file to facebook group with cURL


Czworan

Recommended Posts

Hi.

I'm working on some program. It adds new posts to facebook profiles, fanpages and groups. Everything works well, but when I want to create image uploading it just doesn't work (whitepage as result + file probably isn't even send, because of very short sending time).

 

Multipart form sniffed with Firefox looks like this.

 

 

Content-Type: multipart/form-data; boundary=---------------------------13742240526862
Content-Length: 788662

-----------------------------13742240526862
Content-Disposition: form-data; name="fb_dtsg"

AQGlrKAR9le4
-----------------------------13742240526862
Content-Disposition: form-data; name="charset_test"

â¬,´,â¬,´,æ°´,Ð,Ð
-----------------------------13742240526862
Content-Disposition: form-data; name="file1"; filename="h.jpg"
Content-Type: image/jpeg

FILE_CONTENTS_HERE

-----------------------------13742240526862
Content-Disposition: form-data; name="file2"; filename=""
Content-Type: application/octet-stream


-----------------------------13742240526862
Content-Disposition: form-data; name="file3"; filename=""
Content-Type: application/octet-stream


-----------------------------13742240526862
Content-Disposition: form-data; name="caption"


-----------------------------13742240526862
Content-Disposition: form-data; name="return_uri"

/groups/880573151971764?view=group&fc=photo_upload_success
-----------------------------13742240526862
Content-Disposition: form-data; name="return_uri_error"

https://m.facebook.com/photos/upload/?target_id=880573151971764&upload_source=composer&cwevent=intent_media&ctype=inline&referrer=group&session_id=5f737e58-0e23-4270-a8af-8bfa1100f3c5&refid=18
-----------------------------13742240526862
Content-Disposition: form-data; name="target"

880573151971764
-----------------------------13742240526862
Content-Disposition: form-data; name="ref"

m_upload_pic
-----------------------------13742240526862
Content-Disposition: form-data; name="album_fbid"


-----------------------------13742240526862
Content-Disposition: form-data; name="csid"

5f737e58-0e23-4270-a8af-8bfa1100f3c5
-----------------------------13742240526862
Content-Disposition: form-data; name="ctype"

advanced
-----------------------------13742240526862
Content-Disposition: form-data; name="referrer"

group
-----------------------------13742240526862
Content-Disposition: form-data; name="is_old_composer"

1
-----------------------------13742240526862--

 

 

 

 

I'm loading form to get all inputs and I'm using it as post_parameters for cURL. I'm replacing file1 with filename which is in same directory with PHP file.

 

My $post_params looks like this.

 fb_dtsg=AQH8uaMrlc1w&charset_test=âŹ,´,âŹ,´,ć°´,Đ,Đ&file1=@C:\wamp\www\komek\haha.jpg&file2=&file3=&=Dodaj do albumu&return_uri=/groups/880573151971764?view=group&fc=photo_upload_success&return_uri_error=https://m.facebook.com/photos/upload/?target_id=880573151971764&target=880573151971764&ref=m_upload_pic&album_fbid=&csid=740af77e-8172-4b75-acae-39cd2e49782f&ctype=advanced&referrer=&is_old_composer=&

And I'm posting it with cURL like this.

//example generated $post_params
$post_params = 'fb_dtsg=AQH8uaMrlc1w&charset_test=âŹ,´,âŹ,´,ć°´,Đ,Đ&file1=@C:\wamp\www\komek\haha.jpg&file2=&file3=&=Dodaj do albumu&return_uri=/groups/880573151971764?view=group&fc=photo_upload_success&return_uri_error=https://m.facebook.com/photos/upload/?target_id=880573151971764&target=880573151971764&ref=m_upload_pic&album_fbid=&csid=740af77e-8172-4b75-acae-39cd2e49782f&ctype=advanced&referrer=&is_old_composer=&';
$formAction = 'https://upload.facebook.com/_mupload_/composer/?waterfall_id=d6489f88fb22d5e6f96b3f8a2418020c

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0');
curl_setopt($ch, CURLOPT_URL, $formAction);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$response = curl_exec($ch);

And I get whitepage + following info using CURL_INFO_HEADER_OUT

POST /_mupload_/composer/?waterfall_id=d6489f88fb22d5e6f96b3f8a2418020c 
HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0 
Host: upload.facebook.com 
Accept: */* 
Cookie: mycookies
Content-Length: 410 
Content-Type: application/x-www-form-urlencoded

Content-Length is a way to small (it should contains entire file).

Uploading file takes ~20 seconds with Facebook. Request with cURL takes ~1 second, so it doesn't send my image.

 

I was searching for solution, but everyone tells that to send file with multipart form I need add @ at begining of filepath, but

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.