how to create an event of facebook using facebook application?
further i want to use graph api for that purpose,kindly help me out...
$access_token = 'app_access_token';
$url = "https://graph.facebook.com/app_id/events";
$postdata = "access_token=$access_token&name=$name&start_time=$start_time&end_time=$end_time&description=$description&privacy=$privacy&location=$location&picture=$picture_source";
$event_code = curl_sending_newsfeed_facebook($url, $postdata);
i have already done the creation of event but picture of event is not shown (i mean a picture represents the face of event)
try doing something like this,
$fb = new Facebook(array(
'appId' => YOUR_APP_ID,
'secret' => YOUR_APP_SECRET,
'cookie' => false,
'fileUpload' => true
));
$imageFile = realpath('/path/to/your/example.jpg');
$eventInfo = array(
'name' => 'some title',
'start_time' => time()+32400,
'description' => 'some description',
basename($file) => '#'.$imageFile
);
$result = $fb->api(
'/'.$app_id.'/events',
'post',
$eventInfo
);
echo 'Created event #'.$result['id'];
Related
I'm using FB App to publish posts to my FB pages.
So when i use this code for links, it works.
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true
));
$attachment = array(
'access_token' => $row["token"],
'name' => $_POST["name"],
'picture' => $_POST["picture"],
'message' => $_POST["message"],
'link' => $_POST["link"]);
try
{
$facebook->api("/".$row['id']."/feed", "POST", $attachment);
}
catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}
But, when i want to share pictures as a page:
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => true,
'fileUpload' => true,
'allowSignedRequest' => false
));
$attachment = array('access_token' => $row["token"], 'url' => 'http://image.link.jpg', 'message' => $_POST["message"]);
try
{
$facebook->api("/".$row['id']."/photos", "POST", $attachment);
}
catch(Exception $e)
{
echo('exception caught '.$e->getMessage());
}
The app post picture as user. USER to PAGE.
So i found that i need to use publish_pages permission, but my access token contains both publish_actions and publish_pages. I can't change that because I'm using one access token for a lot of things.
So i have to ask, is there a way to explicitly choose what permissions i want to use from access token. FB API have same code for page and user picture publish /user_id/photos and /page_id/photos.
Need to use Page access token, there's no other way.
I'm using PHP facebook API 3.2.3 to connect to facebook and publicate messages from my page.
Until recently it was working find, but now messages are not publicated.
When i copy returned by FB message ID to create link, it is there, but not on my facewall.
I can accesss to my message by link like this:
https://www.facebook.com/permalink.php?story_fbid=800134770033938&id=659754124150164
It says, that i've publicated link on my fanpage, but it is not visible on wall.
Ofcourse there are all necessary permissions.
Code looks like this:
$fb_fanpage_name = $fb['FBFanpageName'];
$fb_access_token = $fb['FBAccessToken'];
$fb_app_id = $fb['FBApp'];
$fb_secret = $fb['FBSecret'];
$facebook = new Facebook(array(
'appId' => $fb_app_id,
'secret' => $fb_secret,
'cookie' => TRUE,
));
$post = array(
'access_token' => $fb_access_token,
'link' => $fb_url
);
try
{
$res = $facebook->api('/' . $fb_fanpage_name . '/links', 'post', $post);
} catch (Exception $e)
{
$this->zp($e->getMessage());
}
According to FB API on page https://developers.facebook.com/docs/graph-api/reference/v2.3/page/links/ - you can't posting links like this.
Apparently You want post message to feed.
So to do this try :
$post = array(
'access_token' => $fb_access_token,
'link' => $fb_url,
'message' => 'try me!'
);
$facebook->api('/'. $fb_fanpage_name .'/feed', 'POST', $post);
Update : to find this look at page https://developers.facebook.com/docs/graph-api/reference/v2.3/page/feed
i am having a Problem posting a Picture in the Wall of an Event on Facebook.
It is Posting
My current Code is:
$post_array = array(
"access_token" => $facebook->getAccessToken(),
'source' => "#" . realpath("image.png"),
'message' => 'Some Message'
);
$post_id = $facebook->api("/".$event_id['id']."/feed", "POST", $post_array);
Everything is working fine, except for the Image: It won't be displayed.
Any Help out there?
If for Events, Try:
//Setup the Facebook object for file upload
$facebook = new Facebook(array(
'appId' => 'your_app_id_here',
'secret' => 'your_secret_here',
'cookie' => true,
'fileUpload' => true
));
Then:
$file = "image.png";
//The event information array (timestamps are "Facebook time"...)
$event_info = array(
"access_token' => 'your access token",
"name" => "Event Title",
"start_time" => 1290790800,
"end_time" => 1290799800,
"location" => "Your Location",
"description" => "Event Description"
);
$event_info[basename($file)] = '#' . realpath($file);
$result = $facebook->api('me/events','post',$event_info);
Hope it helps
I havent use FBML and PHP SDK for a while and i just can get wallpost work anymore? Last year my code works for fine but now it wont work... so how my app can wallpost again? Help :)
Old code:
<?php
require_once('fb/src/facebook.php');
$config = array(
'appId' => '******',
'secret' => '***********',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$tiedosto = file("http://mydomain.com/doh.txt");
$sids = $tiedosto[$total];
$tiditii = "What's here:";
$message = "";
$text = "Checkout!";
$attachment = array('name' => "$tiditii", 'href' => 'http://mydomain.com/do',
'description' => "$sids
", 'media' => array(array('type' => 'image', 'src' => 'http://mydomain.com/pic.gif',
'href' => 'http://mydomain.com/do')));
?>
<script>
function callback_function(){document.setLocation("http://apps.facebook.com/myapp");};
function publishPost() {
var msg = <?= json_encode($message) ?>;
var attachment = <?= json_encode($attachment) ?>;
Facebook.streamPublish(msg, attachment);
}
</script><p>
<input name="Next" type="button" id="button" class="appMY_APP_ID_button" value="Publish" onclick="publishPost(); return false;"/>
Try something like this using the graph API
$attachment = array(
'access_token' => $access_token,
'message' => "Hello, here is a post",
'name' => "",
'link' => "http://www......",
'description' => "Write here your description",
'picture'=> "http://www.yourserver.com/images/test.jpg";
);
//print_r($attachment);
$facebook->api('/me/feed', 'POST', $attachment);
Facebook PHP SDK can be found here
I don't know much about php.. but why don't you use FB's java script sdk. It's easy to use.
https://developers.facebook.com/docs/reference/javascript/
I am using the following PHP code to post to my page wall. it is okay I can post successfully as admin but I want to post to the wall using the page name (page account). how do I post using the page name or page id. I tried to find good resource to explain Facebook API function but i did not find good documentation for it.
<?
require '../src/facebook.php';
$app_id = "XXX";
$app_secret = "YYY";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
//echo $user;
if(($facebook->getUser())==0)
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access'))}");
exit;
}
else {
echo "i am connected";
}
$attachment = array('message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'example.org',
'description' => 'this is a description',
'picture' => 'http://example.org/image.gif',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$status = $facebook->api('/123456789/feed', 'POST', $attachment); // my page id =123456789
?>
I found the solution to the problem.
To post or to do any task as a page , you need an access token.
Here is my final code after the update, I want to share it with you because I found many people having difficulty with getting the correct access code for a page.
<?
require '../src/facebook.php';
$app_id = "XXX";
$app_secret = "YYY";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$user = $facebook->getUser();
//echo $user;
if(($facebook->getUser())==0)
{
header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos,offline_access,manage_pages'))}");
exit;
}
else {
$accounts_list = $facebook->api('/me/accounts');
echo "i am connected";
}
//to get the page access token to post as a page
foreach($accounts_list['data'] as $account){
if($account['id'] == 123456789){ // my page id =123456789
$access_token = $account['access_token'];
echo "<p>Page Access Token: $access_token</p>";
}
}
//posting to the page wall
$attachment = array('message' => 'this is my message',
'access_token' => $access_token,
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'example.org',
'description' => 'this is a description',
'picture' => 'http://example.org/image.gif',
'actions' => array(array('name' => 'Get Search',
'link' => 'http://www.google.com'))
);
$status = $facebook->api('/123456789/feed', 'POST', $attachment); // my page id =123456789
var_dump($status);
?>
My Facebook OAuth is a little rusty, but I believe this will help:
http://bugs.developers.facebook.net/show_bug.cgi?id=10005
It is the exact bug you are describing, but I have no way of testing that it corrects the issue specifically.
This should help: http://developers.facebook.com/docs/reference/api/page/#feed
It looks like you need the manage_pages permission.