php - Cant get app access token

405

Im desperately trying to get the app access token and failing miserably. Perhaps someone code help

The first way i am trying to get is below :

try {
    $access_t = $facebook->api(
        '/oauth/access_token', 'get', array(
            'client_id'     => $app_id,  
            'client_secret' => $app_secret, 
            'redirect_uri'  => $canvas_page_url
        )
    );
} catch (FacebookApiException $e) {
    echo $e;
} 

I get the error "AuthException: An unknown error has occurred." I confess im not sure what url i should be using for $canvas_page_url So i have used my apps.facebook.com/appname url

Any ideas?

The second way i am trying is :

$token_url = 'https://graph.facebook.com/oauth/access_token?'
    . 'client_id=' . $app_id
    . '&client_secret=' . $app_secret
    . '&grant_type=client_credentials';

And although this does return a access token i am reading that in fact its wron g... Not long enough?

result = 248119721897385|LvWcoYbWu2lQlkEN0HDOeIupSqs

Any ideas on this would be really appreciated as its been doing my head in for some time now.

210

Answer

Solution:

The 2nd method returns what looks like Facebooks new encrypted access token and is probably just fine. Have you tested it out. https://graph.facebook.com/me?access_token={your access token}

I'm guessing it will work just fine for things the app token has access to do. For some operations you'll need other types of tokens like the user token.

People are also looking for solutions to the problem: Grouping multidimensional arrays in PHP by field

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.