Skip to content

Web and Mobile App Development | Custom Application Development Company

  • About Us
  • What we do
    • Application Modernization
    • Cloud & Infrastructure Services
    • Data & Analytics
    • Digital Governance Solutions
    • Digital Strategy and Transformation
    • Enterprise IT Security
    • Geo-Spatial Engineering & Services
    • Enterprise Project Management
    • Innovation & Product R&D
    • Intelligent Automation
    • Software Quality Assurance
    • Superset BI Services
  • Products
    • Orangescrum
    • OConstruction
    • CrmLeaf
    • MyPFSoftware
    • BeePlugin
  • Blog
  • Career
  • Contact Us

Tag: PHP SDK

How To Use PHP SDK For Facebook Posting

Posted on July 1, 2013 by Jay
How To Use PHP SDK For Facebook Posting

There are different ways to connect with your audience. You can create a website, a blog, or any other digital presence to amplify your message. But there are also social media sites that make it easier to reach people directly. In fact, Facebook is the most popular social networking site in the world. According to Statista, by the end of this year, it had more than 1.86 billion monthly active users, which makes it an ideal platform for brands and businesses to promote their products and services. We’ll show you how you can use PHP SDK for Facebook posting so that your brand has a voice on this prominent platform. This article provides insight into what you need to get started as well as helpful tips along the way.

Marketing experts believe that ‘Facebook’ posting is the key to social marketing.

Facebook Posts through Application:

    • For Facebook posting, the first thing we need is the User Access Token.
    • We can get the Access Token when user connects Facebook account to the application.
    • There are two types of page where we can post.1.    Personal Page2.    Fan Page
    • To post on Fan page, we need to get the Page Access Token using the User Access Token.
    • An API call to https://graph.facebook.com/me/accounts?access_token={USER_ACCESS_TOKNE}
    • Facebook PHP SDK: https://github.com/facebook/facebook-php-sdk/tree/master/src

Here I have mentioned some major types of Facebook postings.

Status Update

Update your status or write on your wall in plain text.
We can use “\n\n” for line break.

[sourcecode]$post_type = ‘/$page_id/feed’;
$post_params = array(
‘message’ => “Andolasoft, solutions delivered.\n\n Ruby on Rails Development | CakePHP Development | Android and iPhone Application Development”
);[/sourcecode]

Share Link

Share a link on Facebook. The link can be a website, news feed, YouTube or an image.
Facebook will get the OG (open graph) title, description and image of that link and post it as a link share to the wall.

[sourcecode]$post_type = ‘/$page_id/feed’;
$post_params = array(
‘message’ => “We’re Hiring!”,
‘link’ => “https://www.andolasoft.com/”
);[/sourcecode]

When Facebook finds multiple images, it would choose the first image and post it as a thumbnail.
We can also provide the thumb image to display on the link share.

Note: Facebook use the thumb image greater than size 200*200

[sourcecode]$post_params = array(
‘message’ => “We’re Hiring!”,
‘link’ => “https://www.andolasoft.com/”,
‘picture’ => “https://www.andolasoft.com/blog/wp-content/themes/aware/images/blog_as_logo.png”
);[/sourcecode]

Upload a Photo

Other than image link share, we can upload a photo to Facebook wall.
We need to upload the photo to a Facebook album. There is a default album “timeline” for the wall photos.

To get the timeline album use FQL,

[sourcecode]$fql = “SELECT object_id FROM album WHERE owner=$page_id AND type=’all’”
$fql = urlencode($fql);
$fql_query_url = ‘https://graph.facebook.com/fql?q=’ . $fql . ‘&’ . $access_token . ‘&format=json-strings’;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
$wall_album = isset($fql_query_obj[‘data’][0][‘object_id’]) ? $fql_query_obj[‘data’][0][‘object_id’] : $page_id;[/sourcecode]

You have to provide the relative path of image to upload.
That image might be a link, but save it in your local file system and provide the relative path.

[sourcecode]$imgSrc = ‘/var/www/html/andolasoft/logo.jpg’;
$post_type = ‘/$wall_album/photos’;
$post_params = array(
‘name’ => “Based in Silicon Valley, we design, develop iPhone, iPad, Android & Web application for startups & established businesses”,
‘photo’ => ‘@’.realpath($imgSrc)
);[/sourcecode]

Upload a Video

Other than share a YouTube video, we can also upload video to Facebook.
The video must be in the local file system to be uploaded to Facebook.

[sourcecode]$videoSrc = ‘/var/www/html/andolasoft/tour.flv’;

$post_type = ‘/me/video’;
$post_params = array(
‘title’ => “Andolasoft”,
‘name’ => “Based in Silicon Valley, we design, develop iPhone, iPad, Android & Web application for startups & established businesses”,
‘photo’ => ‘@’.realpath($videoSrc),
‘picture’ => ‘https://www.andolasoft.com/blog/wp-content/themes/aware/images/blog_as_logo.png’
);[/sourcecode]

Post to Facebook using the Facebook PHP SDK.

[sourcecode]$facebook = new Facebook(array(
‘appId’ => APP_KEY,
‘secret’ => SECREATE_KEY
));

try{
$facebook->setAccessToken($access_token);
$fbpost = $facebook->api($post_type, ‘POST’, $post_params);
} catch (Exception $e) {
echo $e->getMessage();
}[/sourcecode]

Conclusion:

Basic permissions required for above operations are,

    • publish_stream
    • manage_pages
    • photo_upload
    • offline_access

Access Token might invalidate for following reasons,

    • The token expires after the allotted expire time
    • The default expire time of Facebook access token is 2 hours, but we can get the extended Access Token up to 60 days.
    • The user changes her password which invalidates the access token.
    • The user de-authorizes your app.

See More: Facebook Login Migration Using PHP SDK

Posted in CakePHP, Mobile App Development, PHP, Software Development, TechnologyTagged CakePHP app development, CakePHP application development, CakePhp Development, CakePHP development company, Cakephp development services, CakePHP ecommerce development, CakePHP Programmer, CakePHP Programmers, CakePHP web app development, CakePHP web application development, Facebook, Facebook Login Migration Using PHP SDK, PHP, PHP SDK, Website

Recent Posts

  • From Data to Decisions: Leveraging AI in CRMLeaf for Smarter Sales Forecasting
  • When Dashboards Started Thinking: The Journey of Superset and AI
  • How Open-Source BI Platforms Like Superset Lower Costs Without Sacrificing Power
  • Superset vs. Other BI Tools: What Makes It Stand Out?
  • Data Governance and Security Best Practices for Superset Deployments

Recent Comments

    Archives

    • May 2025
    • March 2025
    • February 2025
    • January 2025
    • September 2024
    • August 2024
    • July 2024
    • June 2024
    • May 2024
    • April 2024
    • March 2024
    • February 2024
    • January 2024
    • December 2023
    • November 2023
    • October 2023
    • September 2023
    • August 2023
    • July 2023
    • June 2023
    • May 2023
    • April 2023
    • February 2023
    • January 2023
    • December 2022
    • November 2022
    • October 2022
    • September 2022
    • August 2022
    • July 2022
    • June 2022
    • May 2022
    • April 2022
    • March 2022
    • February 2022
    • January 2022
    • December 2021
    • November 2021
    • October 2021
    • September 2021
    • August 2021
    • July 2021
    • June 2021
    • May 2021
    • April 2021
    • March 2021
    • February 2021
    • January 2021
    • December 2020
    • November 2020
    • October 2020
    • September 2020
    • August 2020
    • July 2020
    • June 2020
    • May 2020
    • April 2020
    • March 2020
    • February 2020
    • January 2020
    • December 2019
    • November 2019
    • September 2019
    • August 2019
    • July 2019
    • June 2019
    • May 2019
    • April 2019
    • March 2019
    • February 2019
    • January 2019
    • December 2018
    • November 2018
    • October 2018
    • August 2018
    • June 2018
    • May 2018
    • April 2018
    • March 2018
    • February 2018
    • January 2018
    • December 2014
    • November 2014
    • October 2014
    • September 2014
    • August 2014
    • July 2014
    • June 2014
    • May 2014
    • April 2014
    • March 2014
    • February 2014
    • January 2014
    • December 2013
    • November 2013
    • October 2013
    • September 2013
    • August 2013
    • July 2013
    • June 2013
    • May 2013
    • April 2013
    • March 2013
    • February 2013
    • January 2013
    • December 2012
    • November 2012
    • October 2012
    • September 2012
    • August 2012
    • June 2012
    • January 2012
    • November 2011
    • June 2011
    • March 2011
    • January 2011
    • October 2010
    • September 2010
    • July 2010
    • June 2010
    • May 2010
    • December 2009
    • November 2009

    Categories

    • Advanced CSS
    • AI
    • Amazon Web Services
    • Analytics
    • Android
    • Angular
    • App Development
    • Application Development
    • Artificial Intelligence
    • Artificial intelligence (AI)
    • Asp.net
    • Automation
    • BI/Data Warehousing
    • Business
    • Business & Marketing
    • CakePHP
    • Cloud
    • Cloud Computing
    • Cloud Management
    • Cloud Technology
    • CMS
    • CRM
    • Cross browser testing
    • Cross Platform Framework
    • Cryptocurrency exchange
    • CSS
    • Custom WordPress Plugin
    • dedicated developers
    • Digital
    • Digital Marketing
    • Django
    • Ecommerce
    • Employee Benefits Management.
    • FinTech App
    • Fitness App Development
    • Flexbox
    • Flutter
    • Flutter Mobile App
    • Forex Trading
    • Guest Blogging
    • HealthCare App
    • Hire Developer
    • Hire Developers
    • Hybrid
    • Infographic
    • Information
    • iOS
    • iOS mobile app
    • IoT
    • IT Образование
    • Java
    • Javascript
    • JavaScript Framework Development
    • Laravel
    • Laravel App Development
    • Location-Based Marketing
    • Magento
    • Marketing
    • marketing automation system
    • Marketing automation tools
    • Mobile
    • Mobile App Development
    • Mobile Application
    • No-code development
    • Node
    • NodeJS
    • NuxtJS
    • Odoo
    • Open Source
    • Outsourcing
    • Pentaho
    • Performance Testing
    • PHP
    • Plugin
    • Product Development
    • Productivity App
    • Products and Services
    • Programming Languages
    • Python
    • Python application development
    • Python Developer
    • QA
    • Rails
    • React Native
    • ReactJS
    • Real-Estate
    • Remote Developers
    • Ruby on Rails
    • SaaS
    • SASS
    • Self Goal
    • Service Oriented Architecture
    • Shopify
    • Sober Living
    • Social Media App Development
    • Social Networking
    • Software Development
    • Superset BI
    • Support and Maintenance
    • Technology
    • Technology & Innovation
    • Testing
    • UI Design
    • Uncategorized
    • VueJS
    • Web Designing
    • Web Development
    • WooCommerce
    • WordPress
    • WordPress Websites
    • Финтех
    • Форекс Обучение

    Meta

    • Log in
    • Entries feed
    • Comments feed
    • WordPress.org
    Proudly powered by WordPress | Theme: siard-envytheme by EnvyTheme.