i'm posting some images using the following command:
$url_facebook = "https://api.facebook.com/method/stream.publish?message=".$messaggio."&attachment={\"name\":\"".$title."\",\"href\":\"".$action_link."\",\"caption\":\"".$caption."\",\"description\":\"".$description."\",\"media\":[{\"type\":\"image\",\"src\":\"".$image."\",\"href\":\"".$action_link."\"}]}&action_links=[{\"text\":\"".$link_name."\",\"href\":\"".$action_link."\"}]&target_id=".$target_uid."&uid=".$source_uid."&".$site_token."";
simplexml_load_file("".$url_facebook."");
the image i post in the wall (a group) is generated on the fly from PHP.
this is what happens:
i generate an image and save it to a folder
i post it with the code upon
i exit from the script
the next time a run the script (each hour) i delete all the old
created images , than repeat wath sayid upon
i noticed that the images just when published, are present and existing on the FB wall
BUT
the next time i launch the script (and so the images are deleted from my site) they disappear also from facebook
i understood that the images where uploaded to facebook, so they were not needed anymore on my space....
isn't so ?
i've this doubt also because, if i see on the red x on facebook (in the place of the images)
and i right click "proprerties", i can read :
"https://s-platform.ak.fbcdn.net/www/app_full_proxy.php?app=164286063695472&v=1&size=z&cksum=17f253305254403324260843c7a6989a&src=http%3A%2F%2Fwww.graficisismici.it%2FV6_00%2Ffacebook%2Ffacebook_link_285790.jpg%3F285790"
so it's seem that it's really a link to the original image
can you solve my doubt ?
meanwhile I modified the script to use the new Graph Api
<?php
$user = null;
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
$user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.
if($user == 0) {
/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*/
$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));
echo ("<script> top.location.href='".$login_url."'</script>");
} else {
$user_message = "Message";
$titolo = "Titolo";
$caption = "Caption";
$link_name = "Link Name";
$action_link = "Action Link";
$testo = "Text";
$image = "Image Link";
$target_uid = "XXXXXXXX"; // ID where to publish
//HTTP POST request to PAGE_ID/feed with the publish_stream
$post_url = '/'.$target_uid.'/feed';
try {
$params = array(
'message' => $user_message,
'name' => $titolo,
'caption' => $caption,
'link' => $action_link,
'description' => $link_name,
'picture' => $image,
'actions' => array(
array(
'name' => $testo,
'link' => $action_link
)
)
);
$post = $facebook->api($post_url,"POST",$params);
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
}
?>
I just would like to have a clarification about the image question.
Does the image have to still exist ?
Or once posted, I can delete them, as they still live on Fb ?
My questione born from the fact that i see (while using the old script in the top of this post) on the error log of my site a lof of row of 404 error (related to the missed images searched from Fb)
i understood that the images where uploaded to facebook, so they were not needed anymore on my space....
This is not the case. Facebook simply caches your content in their CDN. If you delete the source photos, when the content falls out of their cache, their attempt to refresh / re-fill the cache will fail and your users will get a broken image icon.
Does the image have to still exist ? Or once posted, I can delete them, as they still live on Fb ?
You should not delete them.
Related
I want to post activities from page tab app to my own facebook page. I referred many documents to post message to app.
My php code :
$GLOBALS["facebook"] = new \Facebook_Facebook(array('appId' => $facebook_app_id, 'secret' => $facebook_secret,));
$page_info = $GLOBALS["facebook"]->api("/pageid?fields=access_token");
print_r($page_info);die;
if (!empty($page_info['access_token'])) {
$args = array(
'access_token' => $page_info['access_token'],
'message' => 'TEST'
);
$postId = $facebook->api("/pageid/feed", "post", $args);
But pageinfo variable has only id. I'm not getting access_token. Any idea what else need to be done?
We need manage_pages permission which we can get it using https://www.facebook.com/dialog/oauth?client_id=client_app_id&client_secret=9ea3e2eff7c65b1fcf1a633da&redirect_uri=YOUR_REDIRECT_URL&scope=read_stream,publish_stream,offline_access,manage_pages.
After that using above code we will get access token which can be used to publish to our page
I have used this code for auto post on my facebook fan page
<?php
// Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/
require ('facebook.php');
define('FACEBOOK_APP_ID',"YOUR-APP-ID");
define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET");
$user = null;
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
$user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.
if($user == 0) {
/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*/
$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));
echo ("<script> top.location.href='".$login_url."'</script>");
} else {
try {
$params = array(
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png",
);
$post = $facebook->api("/$user/feed","POST",$params);
echo "Your post was successfully posted to UID: $user";
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
}
?>
But I need to post on my facebook fan page with my fan page name, this scrpit work so good but this code post on my fan page with my admin account and not like my fan page.
PLZ HELP ME :(
I think you need to take a look to this article carefully, I did it using the steps mentioned there.
Just put you token here:
https://graph.facebook.com/me/accounts?access_token=token
Then you will find the access token for posting as a page.
Hope that helps.
I want to create a post with web site preview. It must be similar as on screenshot.
How do I create a post with web preview? I want to add it on pages.
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:#"Post with web preview", #"message", nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed", myself.pageID]
parameters:dict HTTPMethod:#"POST" completionHandler:nil];
More info about posting links (what you call "post with web site preview") here:
http://developers.facebook.com/docs/reference/api/link/
I asumme you have your Facebook APP with your permissions set, and that you're using PHP-sdk classes. Anyway, the proccess is the same for any language, just changing the way you write it. Also, you need the user Access Token with the proper permission set.
Using the PHP-sdk from Facebook, process would be:
// Load FB class, and init it
require_once("facebook.php");
$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$facebook = new Facebook($config);
// You set the User Access Token (you need to have it previously to this: Because you
// requested before, or because you obtain it from Facebook)
$facebook->setAccessToken( $user_access_token );
try {
// Set the link params:
if ( isset($config['link']) ) {
$args = array(
'link' => $link_url //Url to be linked
, 'name' => $link_titulo //Box title
, 'description' => $link_descripcion //Box Description
, 'picture' => $link_foto //Photo to be posted
, 'message' => $link_message //Message over the "link box"
);
// Post in the User/FB_Page wall
$facebook->api('/me/feed', 'post', $args);
}
} catch (FacebookApiException $e) {
$fbError = $e->getResult();
$result = array(
'tipo' => 'error'
, 'code' => $fbError['error']['code']
, 'text' => $fbError['error']['message']
);
print_r($result);
}
Update
After reading your answer to my comment, I think you're looking just for the CSS and the layout. You can find something to achive the post formatting here:
http://jsfiddle.net/5NYD5/3/
This can be done using multiple ways,
If you are using facebook API then its easy, just like on FB(image will be automatically fetched)
Dim fb As FacebookClient = New FacebookClient('access_token')
Dim args As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
args("message") = "Your Message to be posted"
args("link") = "http://www.example.com"
fb.Post("/me/feed", args)
I hope this will do,
else if you are not using FB API then its comparatively long way to grab image or create snapshot, of site manually. Just like search engine crawlers crawl after entering website. Its long way but yes possible.
Isn't possible facebook allow us from my apps post or share image to user wall and then at the same time the user image will store in my fan page album?
And suggestion and opinion how to do it? hopefully you guy able provide some code for me
step1
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,user_photos'
)
);
step2 , 4 ,5
$file='images/'.$_FILES["file"]['name'];
if( move_uploaded_file($_FILES["file"]["tmp_name"],$file))
{
$facebook->setFileUploadSupport(true);
$post_data = array(
'name'=>$_POST['album'],
'description'=>$_POST['album']
);
$data['album'] = $facebook->api("/me/albums", 'post', $post_data);
//$file = $file_name;
$post_data = array(
"message" => $_POST['message'],
"source" => '#' . realpath($file)
);
$album_id = $data['album']['id'];
$data['photo'] = $facebook->api("/$album_id/photos", 'post', $post_data);
}
it is possible...steps
take user publish stream permissions - scope - publish_stream,user_photos
set application for uploading image..setFileUploadSupport(true);
send the image to users wall using feed api
fetch user photo
Upload it on pages' album by albums api
I have a Facebook app which is interested in whether users like or unlike specific pages. I want to offer a link to unlike a page, as so far as I know there is no way to unlike a page programmatically using the Graph API.
Facebook provide a like button, but (again, so far as I know) no unlike button. How can I present an option to unlike a page without saying "Click here to go to the page, scroll down to the miniscule unlike link and click it"?
You can issue a DELETE request to the page_id
suppose the page id is 1234567890123
place the link as on the a page as:
Unlike
Now collect the GET parameter in the unlike.php file and fire a DELETE request through the graph api:
<?php
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true
));
$session = $fb->getSession();
if (empty($session))
{
$loginUrl = $fb->getLoginUrl();
echo "<script>window.top.location='{$loginUrl}';</script>";
exit;
}
$fb_liked_page = $_GET['d']; //COLLECT THE PAGE ID HERE
try
{
$status = $fb->api("/{$fb_liked_page}/likes", 'DELETE');
if ($status)
{
echo "Success, Unliked!";
}
else
{
echo "Could not unlike this page.";
}
}
catch (Exception $e)
{
var_dump($e);
}