Code Monkey home page Code Monkey logo

simple-facebook-api's Introduction

simple-facebook-api

a very simple API to gain access to the facebook REST library. php based. no namespaces.

#USAGE

$api = new SimpleFacebookApi;
$api->setConfig(array("appid", "apikey", "a shortlive accesstoken"));
$api->addPostToPage("a_pageid",array("message"=>"helo","link"=>".."));
$api->addPostToWall(array("to"=$user_id, "message"=>"helo","link"=>".."));

#VERY IMPORTANT

1. Facebook OpenGraph Explorer is your best friend.
2. Google is your best friend too.
3. You must create an Application in https://developer.facebook.com

simple-facebook-api's People

Contributors

christiansalazar avatar

simple-facebook-api's Issues

TIPS: Using Page Tokens

A page token allows you to post a message to a page authored by the page itself instead of your own name.

  1. To publish a post to a page you send a POST REQUEST to this edge (link) having this fields: "message"=>"the message to be sent to that page"

    https://graph.facebook.com/v2.1/PAGE_ID/feed

You need an access_token, using the GraphExplorer you can create an Access Token for testing, go to the graph explorer by navigating to:

https://developers.facebook.com/tools/explorer

If you debug this access token (that one obtained via graph explorer) then you may get notified about this access token has no PROFILE_ID:

App ID  301787956693381 : ascinformatix
User ID 484896668316843 : Christian Salazar
Issued  Unknown
Expires 1412967600 (in about an hour)
Valid   True
Origin  Web
Scopes  public_profile, manage_pages, publish_actions

When this situation occurs then when you post the message it will be authored by you, instead of the page. That facebook visitors users may get confused because they think you are sending messages to that page. In the opposite case: you want from your visitors to think that this messages are sent by the page itself

How to obtain a page-access-token

Reference:

https://developers.facebook.com/docs/facebook-login/access-tokens#pagetokens

  1. go to the menu tools/"Graph API Explorer" in:
    https://developers.facebook.com/

  2. choose the application, that one designed to be used to publish messages to a PAGE.

  3. click button "Get Access Token" , then "clear" button, close dialog box by clicking "cancel", then reopen it again and now choose the following "extended permissions", as result you may obtain a short-lived access token.

    manage_pages, publish_actions

  4. A pop-dialog will shown, asking you grant permissions to that application. Accept.

  5. A short-lived access token is created for you WITHOUT THE PROFILE_ID, dont worry. Use that access token to go to the next step

  6. Debug the obtained Access Token (click Debug) in order to get your USER_ID.

    App ID  787119291327245 : YOUR_APP_NAME
    User ID 491662644306912 : Christian Salazar
    Issued  Unknown
    Expires 1412974800 (in about an hour)
    Valid   True
    Origin  Web
    Scopes  public_profile, manage_pages, publish_actions
    
  7. Make a GET query to this UNVERSIONED edge, using the obtained USER_ID:

https://graph.facebook.com/491662644306912/accounts (DONT BROWSE TO IT, INSTEAD, COPY THE "491662644306912/accounts" INTO THE Graph Api Explorer and click SUBMIT)
8. As result you will see:

{
"data": [
  {
    "category": "Internet/software",
    "name": "ASC Informatix C.A.",
    "access_token": "CAALL4X3BYw0BACykg4uvWBITJCTyldGiODjQZAFadmAPptYAmZBVuTpbLR61pgLcygss4YBBfWh6SfMfXVDpJDNYKwexOCLtHzEwERN8LiKGwQsFky7ohoWSdyNcWW8quuBmepc39lufgZBT18OSDqarkTZBPJtoqUZByP7ZBT3De9teJQhSfQI3ZAQMDswia2Aq9Ei6NPpmAZDZD",
    "perms": [
      "ADMINISTER",
      "EDIT_PROFILE",
      "CREATE_CONTENT",
      "MODERATE_CONTENT",
      "CREATE_ADS",
      "BASIC_ADMIN"
    ],
    "id": "479413205454312"
  }, 
  1. The required "page access_token" is that one in the result under the field labeled: "access_token", try debugging it and now you will see the "Profile ID" field. Future messages sent using this access token using the edge "/v2.1/page_id/feed" will be authored by the ProfileID identity.
App ID  787119291327245 : PropertyWarehousesPageManager
Profile ID  479413205454312
User ID 491662644306912 : Christian Salazar
Issued  Unknown
Expires 1412974800 (in about an hour)
Valid   True
Origin  Web
Scopes  public_profile, manage_pages, publish_actions

ALTERNATIVES

https://developers.facebook.com/tools/debug/accesstoken/?q=ACCESS_TOKEN_HERE

and click "extend access token"

DONE.

setup_access_token

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.