Posting Picture on Event Page - php

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

Related

Post to Facebook with PHP

I have to post on a facebook page, the titles of articles (with link) posted on a blog.
Unfortunately I can only post the link, but without the title. How can I do?
The PHP code I am using is this:
require ("facebook.php");
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXX',
'cookie' => true
));
// id page
$pageId = "136860079786056";
// permanent session token
$permSess = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// writing
$test = $facebook->api(array(
"uid" => $pageId,
"method" => "stream.publish",
"access_token" => $permSess,
"message" => "http://www.mysite.it/functions.php?p=view&id=31", ));
There is a link variable you can use for the link.
Eg
"link" => "http://google.com",
"message" => "The search engine we can't mention"

create event of facebook using facebook application

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'];

Facebook app: how to publish wallpost

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/

How to add profile image to event using the new php graph api

Using the php graph api I want to add picture to an event. So I m looking for some examples for the new graph api !
I'm sorry if the question is a bit unclear. Creating an event facebook use standard pictures of 31
calendar icon of facebook
http://i.stack.imgur.com/w7tMp.png in monocolor and color
I ( and many other person ) want to replace this picture using php as you can do it via the facebook page.
All descriptions in the internet fail.
I use the following code
$name= $parameter['betreff'];
$beschreibung=$parameter['thema'];
start_time = $parameter['anfangsdatum'] . " " . $parameter['anfangszeit'];
$ort="" . $parameter['ort'];
$picture='http://www.tvwehen.de/facebook/facebook_plan_event/news.png';
$privacy="CLOSED";
$event_param = array(
'access_token' => $access_token,
'page_id' =>$fanPageId,
'name' => $name,
'start_time' => $start_time,
'description' => $beschreibung,
'location' => $ort,
'pic_big' => $picture,
'pic_small' => $picture,
'logo.png' => $picture,
'privacy' => $privacy
);
$event_id = $facebook->api($fanPageId . "/events", "POST", $event_param);
The event is created on the fanpage but without any picture ! Why ?
Your question is a bit unclear, but assuming I've understood you correctly, you simply want a users profile picture? That can be found here:
http://graph.facebook.com/username/picture
So mine would be at http://graph.facebook.com/filip.soderholm/picture
You may also use the userId instead of the username if you have that.
You can get help from this address: https://gist.github.com/1178154
<?php
/**
* Implementation of hook_nodeapi
*/
function hps_the_hook_nodeapi (&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($node->type == 'event') {
if ($op == 'insert') {
dpm($node);
//require_once(drupal_get_path('module', 'hps_the_hook') . '/lib/facebook-php-sdk/src/facebook.php');
$facebook = new Facebook(array(
'appId' => '193560340711521',
'secret' => 'secret',
'fileUpload' => true,
));
$page_id = "161330440592966";
$location = $node->field_location[0]['value'];
$from_date = $node->field_date[0]['value'];
$to_date = $node->field_date[0]['value2'];
$image_path = $node->field_image[0]['filepath'];
$event_param = array(
"access_token" => 'access_token',
"name" => $node->title,
"start_time" => strtotime($from_date),
"end_time" => strtotime($to_date),
"location" => $location,
"page_id" => $page_id,
"picture" => "#".realpath($image_path),
"source" => "#".realpath($image_path),
);
$facebook->setFileUploadSupport(true);
try {
dpm($event_param);
$event_id = $facebook->api("/161330440592966/events", "POST", $event_param);
dpm($event_id);
}
catch (Exception $ex) {
dpm($ex);
}
}
}
}
?>

Problem with posting to Facebook Page using PHP script as Page account

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.

Categories