How to post on directly users wall in Facebook - php

I use this to post on users wall, but it shows a blank page, and the post doesn't appear on my wall :
$url = "https://graph.facebook.com/user_id/feed";
$ch = curl_init();
$attachment = array( 'access_token' => access_token_here,
'name' => "Rave Kenya",
'link' => "www.youtube.com",
'description' => 'Testing a new facebook app',
'message' => 'Tested',
);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result =curl_exec($ch);

Why reinvent the wheel and not use facebook php library?
And a step-by-step instructions are available at "5 Steps to publish on a facebook wall using php"

Related

How to aduser with admin access while creating ad account facebook marketing api

I am trying to create ad account in Facebook business manager via Facebook marketing and graph API using following code.
$attachment = array('access_token' => $this->accessToken,
'name' => $associative_arr['name'],
'currency' => $associative_arr['currency'],
'timezone_id' => $associative_arr['timezone_id'],
'end_advertiser' => $this->mybusinessId,
'media_agency' => 'NONE',
'partner' => 'NONE',
'access_type' => 'OWNER',
'permitted_roles' => 'ADMIN'
//'user_role' => '1001'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$this->apiVersion.'/'.$this->mybusinessId.'/adaccount');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
$dcde = json_decode($result);
curl_close ($ch);
It successfully creates ad account but does not add me as a user in people with administrative access.
Can anyone give me suggestion what can be the reason?
Once the ad account is created, you'll need to make another call which will add the user with the required permissions.
$attachment = array(
'access_token' => $this->accessToken,
'business' => '<business_id>',
'user' => '<user_id>',
'role' => 'ADMIN'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$this->apiVersion.'/act_<AD_ACCOUNT_ID>/userpermissions');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
$dcde = json_decode($result);
curl_close ($ch);

auto share links using php curl

I want to auto share links in my facebook wall using this script :
$attachment = array(
'email' => 'mail',
'password' => 'password',
'access_token' => 'my token',
'message' => "my message",
'name' => 'name',
'link' => 'my_url',
'description' => "my description"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/me/links');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.001 (windows; U; NT4.0; en-US; rv:1.0) Gecko/25250101');
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$json = json_decode($result);
$post_id = $json->{'id'};
curl_close($ch);
at the began it worked for me but after trying it for 7 times or more i got this error :
{ "error": { "message": "(#100) The parameter url is required", "type": "OAuthException", "code": 100 } }
how can I fix it
links
Create
You can post a link on the user's behalf by issuing an HTTP POST request to PROFILE_ID/feed with the publish_stream permissions.
The other fields are taken from the metadata of the page URL given in the 'link' param.
If the create is successful, you get the following return.
Refer to: https://developers.facebook.com/docs/reference/api/user/#links
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/me/feed');

Post image on user wall with app message followed by app URL

In my application, I am posting images on walls, and it works fine, but now my requirement is to print my app's URL with a message and have it so that when a user clicks on the link, he is redirected to my app.
You can use curl method, Am using this and it works fine
$attachment = array(
'access_token' => "accesstoken",
'caption' => "Hey -- this is caption",
'description' => "Your Desc",
'link' => "http://www.example.com/",
'picture'=> "path/image.png"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/XXXXXX/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);

Php Facebook - Upload Image from External Source

Good morning fellows,
I am having an issue with facebook api:
is it possible to upload a photo from an external source? For instance, point out an URL and the Facebook will get that...
My code is right next $args = array(
'message' => 'Photo from application',
'source' => $im_url
);
$url = 'https://graph.facebook.com/'.$album_id.'/photos?access_token='.$token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);the $im_url should point out to an external picture, like store on imageshack,etc.The error it gives me is {"error":{"message":"(#324) Requires upload file","type":"OAuthException"}}
Instead of "source", the term is "url". Problem solved
$args = array(
'message' => 'Photo from application',
'url' => $im_url

How to use array values in another array

My Facebook app publishes a story to the user wall with an http post:
$args = array('access_token' => $ACCESS_TOKEN,
'message' => 'testing message',
'picture' => $appin_logo,
'link' => $appin_canvas_url,
'name' => $appin_name,
'caption' => $post_score,
'description' => $post_rfs,
);
$ch = curl_init(); $url = 'https://graph.facebook.com/me/feed'; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $args); $data = curl_exec($ch); curl_close($ch);
That works all fine, except for one thing: $post_rfs is an array. I'd like to output its values in a neat way, with a comma after every value i.e.. What should I do?
Thanks in advance.
Try this:
implode(', ', array_values($post_rfs));

Categories