mercredi 8 mars 2017

How to get access_token for V5 facebook PHP without login?

I have created application by checking all the checkbox of the permission.enter image description here

I want to auto post to selected page. I have used the following code. When I am login to facebook then it will allow me to post to that selected page.

<?php
        $fb = new Facebook\Facebook([
            'app_id' => '{APP-ID}',
            'app_secret' => '{APP-SECRET}',
        ]);
        $linkData = [
            'link' => 'http://www.example.com',
            'message' => 'Auto',
          ];
        try {
            $response = $fb->post('/me/feed', $linkData, '{access-token}');
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
            echo 'Graph returned an error: ' . $e->getMessage();
            exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
            echo 'Facebook SDK returned an error: ' . $e->getMessage();
            exit;
        }
            $graphNode = $response->getGraphNode();
            echo "<pre>"; print_r($graphNode);
    die(); 
    ?>

I have got {access-token} by copying the token from the text-box nearby "Get Token" button.I want to get this {access-token} when I am not logged in.Please help. I am trying from the last two days.

I have got following errors:

  1. An access token is required to request this resource. An active
  2. access token must be used to query information about the current user.



Aucun commentaire:

Enregistrer un commentaire