Using facebook graph api explorer to post picture/link on feed - facebook

I'm try to post to a feed using the facebook graph api explorer (I'm obtaining the token through that).
Usually, when you post a link manually in the feed, a summary is created. When I post a link through the graph explorer api app, it shows up as a regular link.
enter code here
$graph_url = "https://graph.facebook.com/".$_POST['group_id']."/feed";
$postData = array(
'access_token' => $_POST['token'],
'message' => $_POST['message'],
'name' => 'name',
'picture' => urlencode ('http://wildfireapp.files.wordpress.com/2010/05/img-payingfbcustomers1.png'),
'link' => urlencode ('http://www.google.com'),
'scope' => 'publish_stream');
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $graph_url,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true
));
$result = json_decode(curl_exec($ch));
curl_close($ch);

Related

Clash between `scheduled_publish_time` and `tags` on Facebook graph API /page/feed post endpoint

I can make a scheduled post fine.
I can make a post with tags to users fine.
If I try and do both together the response I get from facebook is "(#100) Invalid parameter"
Here's the code:
$fb = new Facebook\Facebook([
'app_id' => FB_APP_ID,
'app_secret' => FB_APP_SECRET,
'default_graph_version' => 'v2.9'
]);
//Post property to Facebook
$linkData = [
'link' => 'http://www.example.com/',
'message' => 'Test',
'place' => 3333333333333333,
'tags' => [55555555],
'published' => false,
'scheduled_publish_time' => 1498580000
];
try {
$response = $fb->post('/mypageid/feed', $linkData, FB_APP_ACCESS_NON_EXPIRES);
Any ideas? There's no documentation on https://developers.facebook.com/docs/graph-api/reference/v2.9/page/feed that suggests these two properties shouldn't work together, and common sense doesn't immediately suggest a reason that they wouldn't.

Post content to Facebook through the back end

Using PHP, can I post content to a Facebook page when I add something to my website? In this instance I'm creating a news post on our website but want to know if Facebook is capable of receiving the same content to display on our page?
You can use the Facebook php API to post on the Facebook page
$attachment = array(
'message' => '',
'name' => '',
'link' => '',
'description' => '',
'picture' => "",
'actions' => array( array(
'name' => 'Get Search',
'link' => 'http://www.google.com'
))
);
$pageid = '';
$facebook->api('/'.$pageid .'/feed?access_token='.$facebook->getAccessToken(),'post',$attachment);

Facebook API access outside of apps.facebook.com

I am attempting to build a website that utilizes facebook auth based setting created through facebook.com/developers
Can I access a user’s wall (to post), multi friend selector and other elements if the website is hosted outside of facebook.com (apps.facebook.com) realm?
Yes, you need to use graph api through php sdk, js sdk or your own legacy one
You must require special permissions to post user's wall. Use a standard api mechanism to get access_token from user. Make sure user accepted the application permissions requirements such as offline_access, publish_stream etc.
public function friend_off()
{
$home_view = 'offline';
$this->load->library('facebook',array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$this->load->database();
$this->db->where('status', 'A');
$db_user = $this->db->get('users');
//$db_user = $this->db->where('access_pass',$val));
$row = $db_user->result();
//print_r($row);
//friends list
$post = array(
'from' => array(
'access_token' => '1302623452|1212291707|Dgz0FpB0wL0n5PYLy2x--5iGRVo',
'name' => 'Syama Varyar',
'id' => '100002653867222'
),
'to' => array(
'name' => 'Vishnu Jayendran',
'id' => '558987909'
),
'caption' => 'Test Caption',
'description' => 'Test Description',
'picture' => 'http://www.najeem.com/bird-2003.gif',
'message' => 'Test Message >> '. date('Y-m-d H:i:s'),
);
$friends = $this->facebook->api('/100002653867222/friends?access_token=1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
//$this->print_p($friends);
$this->facebook->setAccessToken('1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
if(!($res = $this->facebook->api('/me/feed', 'POST', $post)))
{
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}

Facebook OAuthException: Error validating application

I have a simple PHP page that is going to be used to post a message to my own wall.
I've obtained an offline_access token that has "read_stream" and "publish_stream" permissions.
define('FB_APIKEY', 'MY_APP_KEY');
define('FB_SECRET', 'MY_APP_SECRET');
define('FB_SESSION', 'MY_OFFLINE_TOKEN');
require_once('facebook.php');
try {
$facebook = new Facebook(FB_APIKEY, FB_SECRET);
$facebook->api_client->session_key = FB_SESSION;
$attachment = array(
'message' => 'some meesgae',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'mylink.com',
'description' => 'this is a description',
'actions' => array(array(
'name' => 'Get Search',
'link' => 'google.com'
))
);
$result = $facebook->api('/me/feed?access_token=' . FB_SESSION,
'post',
$attachment);
var_dump($result);
} catch(Exception $e) {
echo $e;
}
When I run this, I get "OAuthException: Error validating application".
I confirmed that my offline token is good. When I go to https://graph.facebook.com/me?access_token=[MY_OFFLINE_TOKEN], it returns my public profile in JSON format correctly.
So, I'm thinking I'm doing something wrong with the API call somewhere but for the life of me I can't seem to figure it out. I've been wrestling with this issue for the last two days. Could someone please help! :(
You don't have APP ID here. And make calls like this:
require_once('facebook.php');
$facebook = new Facebook( array(
'appId' => 'APP_ID',
'secret' => 'APP_SECRET',
'cookie' => true
));
try {
$attachment = array(
'message' => 'some meesgae',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'mylink.com',
'description' => 'this is a description',
'actions' => array(array(
'name' => 'Get Search',
'link' => 'google.com'
))
);
$attachment['access_token'] = $offline_access_token; // add it to the array
$result = $facebook->api('/me/feed', 'POST', $attachment );
var_dump($result);
} catch(Exception $e) {
// error_log( $e ); // should use something like this when in production
echo $e;
}
Untested, but should work. Let me know if it doesn't.

Creating an event-invite using the old REST API

I cannot do the following with the Graph API, so I'm trying to do it with the old REST API,
but without any success... No error message, but also no invite.
$restApi = $facebook->api(array(
'method' => 'events.invite',
'eid' => $eid,
'uids' => $testuserId,
'personal_message' => 'testing',
'access_token' => $accesstoken,
));
print '<pre>' . print_r($restApi, true) . '</pre>';
Or maybe some of you know a better way...
There is a open Vote on Event Invites with Graph API at the FB Bugzilla http://bugs.developers.facebook.net/show_bug.cgi?id=10070
And I think your problem is that you need an array of uids try:
$restApi = $facebook->api(array(
'method' => 'events.invite',
'eid' => $eid,
'uids' => array($testuserId),
'personal_message' => 'testing',
'access_token' => $accesstoken,
));
print '<pre>' . print_r($restApi, true) . '</pre>';
-michael