Jump to content

Search the Community

Showing results for tags 'facebook api php sdk page'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi. I am currently working on a script designed so that the admin of a website can post onto a Facebook wall for his companies Page. This is my first ever time working with Facebooks SDK API and I'm finding loads of outdated tutorials and scripts out there so I'm really stumped. This is what I've written so far: // Get these from http://developers.facebook.com $api_key = '**************'; $secret = '*********************************'; $token = '**************|*************************'; $pageid = '*******************'; // ^^ ABOVE IS THE API, SECRET TOKEN INFO ETC WHICH IVE OMMITTED include_once '****/*****/src/facebook.php'; //ommitted link to fb sdk $facebook = new Facebook(array( 'appId' => $api_key, 'secret' => $secret, 'cookie' => true )); $user_id = $facebook->getUser(); //works //END OF FACEBOOK REQUIRED INFORMATION echo "USER ID: ".$user_id."<br />"; //it succesfully gets user id if($user_id) { // We have a user ID, so probably a logged in user. // If not, we'll get an exception, which we handle below. try { $facebook->setAccessToken(qa_opt('facebook_page_access_code')); // Try to extend token $access_token = $facebook->getExtendedAccessToken(); $attachment = array( 'access_token' => $token, 'message' => 'message here', 'link' => 'http://domain.com/index.php', 'picture' => 'http://domain.com/images/image.png', 'name' => 'Name', 'description'=> 'Latest news for domain.com.' ); /// THE BELOW LINE IS CAUSING SOME SORT OF ERROR $res = $facebook->api('/'.$pageid.'/feed','POST',$attachment); echo "Post done!"; } catch(FacebookApiException $e) { // If the user is logged out, you can have a // user ID even though the access token is invalid. // In this case, we'll get an exception, so we'll // just ask the user to login again here. $login_url = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' )); echo 'Please <a href="' . $login_url . '">login.</a>'; error_log($e->getType()); error_log($e->getMessage()); } I didn't include the entire script because I believe the problem mainly concerns the following piece of code from the above: $res = $facebook->api('/'.$pageid.'/feed','POST',$attachment); The thing is, when the above line is commented (and thus not executed by the script), the script runs without errror and displays "post done!" If I change the $res variable to: $res = $facebook->api('me/feed', 'post', array( 'message' => 'Hello World!' )); The script will post but it will post to my wall. However, I need it to post to the Facebook Page (i.e. a company page) and I know I need to use something like the $res variable I first cited from my script. So the jist of my question is: what am I missing/doing wrong that won't let me post to a facebook page as the pages admin? Thanks guys.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.