Api facebook php share

How to use Facebook Sharer in PHP

On sites like buzzfeed.com their share buttons are still an important source of referral.

Don’t use the sharer, it has been deprecated and is no longer supported:

The Share button has been deprecated in favor of the Like button, and will no longer be supported.
Please use the Like button whenever possible to drive maximum traffic to your apps.

What happened to the old Share button?

We deprecated the Share Button when we launched the Like button, because the Like button improves clickthrough rates by allowing users to connect with one click, and by allowing them to see which of their friends have already connected.

Well, your code looks legit I think, make sure that you have the full url (including http ) and that it’s url encoded, like in the example in the documentation: http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.sadtrombone.com%2F&t=Sad%20Trombone . But since it’s not supported yet, it can behave strangely and there’s not much you can do about that other than the right thing which is to stop using it. Why would you want to use deprecated, unsupported feature? It’s a very bad practice.

If I use the like button instead of facebook sharer. how can i change the content of the share option?

Just use the Step 1 — Get Like Button Code section in the Like button documentation page, then click the Get Code button. You can specify the url to «like».

Источник

how can I share an Image using Facebook Graph API like share button

I want to open share pop up window of facebook when user clicks on a particular link (Not the share button). I want to do this in php and want to share an image. Note: I want to provide the source of the image which comes dynamically. Can any one help me please? Please ask for more information if you want. Thank you. Update: Below is my code: The main page where the link is:

$("#post_image_href").click(function(e) < if($('.prodct_personalize_but a').html() != 'Cancel' && $('#zoom1').length>0 ) < $(this).attr('href','https://www.facebook.com/sharer/sharer.php?u='+$('#zoom1').attr('href')); >else if ($(".image-main-container").css('display') != 'none') < if ($('.product_box23').css('display') != 'none') < e.preventDefault(); setProperDynamicTextPosition(); var data = $('#personalise_form').serialize(); $('#loader_img').show(); $.post(ajaxurl, data + '&action=save_personalise_image', function(response) < if (response != '' && response != undefined) < var Aryresponse = response.split('###'); $("#post_image_href").attr('href','https://www.facebook.com/sharer/sharer.php?u=' + Aryresponse[0]); document.location.href = $("#post_image_href").attr('href'); $('#loader_img').hide(); >>); > > >); 

Link which is created when I click on the Facebook link and go to facebook page: In share dilog box: the current url of the browser and in the address bar: the updated link. For Ex. https://www.facebook.com/sharer/sharer.php?u=https://www.picpixa.com/wp-content/plugins/create-own-object/test-img/final_ProductImage_1405751994-2197.png Please let me know if you want more information. Update In JS Function: I have made change in my js (click event function): Below is the updated function:

$("#post_image_href").click(function(e) < var url=''; if($('.prodct_personalize_but a').html() != 'Cancel' && $('#zoom1').length>0 ) < //$(this).attr('href','https://www.facebook.com/sharer/sharer.php?u='+$('#zoom1').attr('href')); url = 'https://www.facebook.com/sharer/sharer.php?u='+$('#zoom1').attr('href'); console.log("If: "+ $('#zoom1').attr('href')); console.log("URL: "+ url); >else if ($(".image-main-container").css('display') != 'none') < if ($('.product_box23').css('display') != 'none') < e.preventDefault(); setProperDynamicTextPosition(); var data = $('#personalise_form').serialize(); $('#loader_img').show(); $.post(ajaxurl, data + '&action=save_personalise_image', function(response) < if (response != '' && response != undefined) < var Aryresponse = response.split('###'); //$("#post_image_href").attr('href','https://www.facebook.com/sharer/sharer.php?u=' + Aryresponse[0]); url = 'https://www.facebook.com/sharer/sharer.php?u=' + Aryresponse[0]; console.log("Else: "+ Aryresponse[0]); console.log("URL: "+ url); window.open(url, "popupWindow", "width=450,height=400,scrollbars=no"); //If I don't use this the pop up don't open. //In fact this is og no use as this is not opening but still I have to put this here to run below winodw.open. $('#loader_img').hide(); >>); > > console.log("The URL is: "+url); window.open(url, "popupWindow", "width=450,height=400,scrollbars=no"); >); 

Another Update: Imp. Info: I thought that this might me the issue of the Meta Tags. And it is. I am giving all the required meta tags in the main page but when I did the debug of the url I am passing it is giving me the below result. Click here to see the result Can anyone find me a solution?

Читайте также:  Conda install opencv python

Источник

share an image in facebook via php

The above code is to share an image on facebook via php. but the image cannot display in my account. how to share an image on facebook using php. please help me friends.

The Share dialog does not take any additional parameters besides the URL to share any more – all other information (title, description, image) will be taken from the Open Graph meta tags that the document under that URL contains.

2 Answers 2

Here is the code you need to share a link to Facebook using PHP. With small changes you can use this code to post just a message (without link), or to upload a photo in a Facebook album.

 "YOUR_ACCESS_TOKEN", // see: https://developers.facebook.com/docs/facebook-login/access-tokens/ "message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook", "link" => "http://www.pontikis.net/blog/auto_post_on_facebook_with_php", "picture" => "http://i.imgur.com/lHkOsiH.png", "name" => "How to Auto Post on Facebook with PHP", "caption" => "www.pontikis.net", "description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation." ); // post to Facebook // see: https://developers.facebook.com/docs/reference/php/facebook-api/ try < $ret = $fb->api('/YOUR_FACEBOOK_ID/feed', 'POST', $params); echo 'Successfully posted to Facebook'; > catch(Exception $e) < echo $e->getMessage(); > ?> 

Источник

Post to Facebook Wall from Website using PHP

Facebook is the most popular social media and shares on the Facebook wall are the most used activity by its user. Facebook share option is a common and required feature for every web application. We can easily share the post on Facebook by manually or from the script. In this tutorial, you’ll learn how to post activity on Facebook wall from website using PHP and Facebook API.

Читайте также:  Html email table styling

Post to Facebook wall is useful when you want to post dynamic content to Facebook from the website. Here we’ll build a simple PHP script to publish Facebook post from website using Facebook PHP SDK. This functionality lets the user submit the post (message, picture, link, text content) on their Facebook timeline from the website using PHP SDK v5.0 and Facebook Graph API.

Before getting started to post to Facebook wall using PHP, take a look at the files and folders structure.

post-to-facebook-wall-from-website-php-sdk-files-structure-codexworld

Facebook Apps Creation

To access Facebook API, App ID & App Secret need to be specified on Facebook API call. You need to create a Facebook App for generating App ID & App Secret. If you’re not already created a Facebook app, visit the link below to create and configure a Facebook App from the App Dashboard.

After completing the Facebook App creation and configuration you’ll get the App ID and App secret. Copy this App ID and App Secret of your Facebook App for later use.

Facebook SDK for PHP v5.0

All Facebook PHP SDK files are included in the facebook-php-sdk/ directory, place the facebook-php-sdk/ folder into the root directory. You don’t need to download it separately, Facebook SDK v5 is included in our source code.

Facebook API Configuration (fbConfig.php)

The fbConfig.php file is used to configure Facebook SDK and connect to Facebook Graph API. Specify your Facebook App ID ( $appId ), App Secret ( $appSecret ), Callback URL ( $redirectURL ), and Permissions ( $fbPermissions ) to connect with Facebook API and working with SDK.

Читайте также:  Бір лшемді массивтер python

Note that: The access token must have the publish_actions permission to post on Facebook wall.

if(!session_id()) session_start();
>

// Include the autoloader provided in the SDK
require_once __DIR__ . '/facebook-php-sdk/autoload.php';

// Include required libraries
use Facebook\Facebook;
use
Facebook\Exceptions\FacebookResponseException;
use
Facebook\Exceptions\FacebookSDKException;

/*
* Configuration and setup Facebook SDK
*/
$appId = 'InsertAppID'; //Facebook App ID
$appSecret = 'InsertAppSecret'; //Facebook App Secret
$redirectURL = 'http://localhost/post_to_facebook_from_website/'; //Callback URL
$fbPermissions = array('publish_actions'); //Facebook permission

$fb = new Facebook(array(
'app_id' => $appId,
'app_secret' => $appSecret,
'default_graph_version' => 'v2.6',
));

// Get redirect login helper
$helper = $fb->getRedirectLoginHelper();

// Try to get access token
try if(isset($_SESSION['facebook_access_token'])) $accessToken = $_SESSION['facebook_access_token'];
>else
$accessToken = $helper->getAccessToken();
>
> catch(
FacebookResponseException $e) echo 'Graph returned an error: ' . $e->getMessage();
exit;
> catch(
FacebookSDKException $e) echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
>
?>

Note that: You’ll find the App ID and App Secret on your Facebook Apps settings page.

Submit Post to Facebook Wall (index.php)

Include the fbConfig.php file to connect Facebook API and get the access token.

If FB access token ( $accessToken ) is available, the following will happen.

  • Access token will be stored in the session that will be used for next time API calls.
  • Post message, name, link, description, and the picture will be submitted to Facebook wall.
  • Post submission status will be shown.

If FB access token ( $accessToken ) is not available, the Facebook Login URL will be generated and the user would be redirected to the FB login page.

Conclusion

We’ve tried to provide a simple way to share the post to Facebook wall from website using PHP. Hope! our script will help you to post on Facebook wall from your website. Also, you can change the post content dynamically by specifying the respective value in $attachment array.

Are you want to get implementation help, or modify or enhance the functionality of this script? Click Here to Submit Service Request

If you have any questions about this script, submit it to our QA community — Ask Question

Источник

Оцените статью