0

I am using below curl code which is based on #unificationengine API to access facebook graph api and post message on facebook:

$post_msg = json_encode(
        array(
            'message' =>
                array(
                    'receivers' =>
                        array(
                                array(
                                    'name'      => 'Me',
                                    'address'   => 'https://graph.facebook.com/v2.5/7/feed?access_token='.$request->access_token,
                                    'Connector' => 'facebook'

                                ),
                        ),
                        'sender'    =>
                        array('address' => 'sender address'),
                        'subject'   => 'Hello',
                        'parts'     =>
                        array(
                                array(
                                    'id'          => '1',
                                    'contentType' => 'text/plain',
                                    'data'        => 'Hi welcome to UE',
                                    'size'        => 100,
                                    'sort'        => 0

                            ),
                        ),
                    ),

                )
            );



    $ch = curl_init('https://apiv2.unificationengine.com/v2/message/send');
    curl_setopt($ch, CURLOPT_USERPWD, "ab33333222b-acb5-49a6-a766-80d991daff41:43433232-33cb-49f0-3333-3fe6c46acb5f");
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_VERBOSE, true); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_msg);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);




    // execute!
    $response = curl_exec($ch);

    // close the connection, release resources used
    curl_close($ch);

    // do anything you want with your response
    var_dump($response);



    return ['label' =>$response];

I am getting invalid access token error with code 498. I referred various posts on this topic but couldn't figure out that what is missing.

How to check validity of facebook access token.

Referenced these questions:

  1. SO question 1

  2. SO question 2

Community
  • 1
  • 1
Always_a_learner
  • 4,585
  • 13
  • 63
  • 112
  • Your access token might have expired. Please reconnect the facebook connection again or refresh the connection by using https://apiv2.unificationengine.com/v2/connection/refresh api. – AMT.in Jan 06 '17 at 12:15
  • I used apiv2.unificationengine.com/v2/connection/refresh and it returned me two parameters in response: 'status': 200 and 'info':'ok'. – Always_a_learner Jan 06 '17 at 12:21
  • My access token looks something like this: EAAZALF1r8QvwBAGLsCZCbIpuZAlYKYZBSrWTC57hhCHp9qW3YS9HwAsICxqkhboK7vcO44KbtMJlUqQ7pyDfJpQED3TFmzgHy5XExG8TUGqGZA3cYWY394NfROjznq2VjSmEqnsdfdfdpa1TrO0aVlkp1AfGfT3vNZB89ZA5ehM8ZACJQZDZD – Always_a_learner Jan 06 '17 at 12:22
  • @AMT.in sometimes I get error 520 unknown error and sometimes I get 498 invalid token error when I call refresh connection curl. Any ideas about this? – Always_a_learner Jan 06 '17 at 12:48
  • The facebook access tokens have a lifetime of about two hours. For longer lived web apps, especially server side, need to generate long lived tokens. Long lived tokens generally lasts about 60 days. UE has a capability to refresh facebook tokens. After adding connection using "https://apiv2.unificationengine.com/v2/connection/add" api call, then you should call "https://apiv2.unificationengine.com/v2/connection/refresh" api to make the short lived token to long lived. – AMT.in Jan 07 '17 at 05:56

1 Answers1

0

The facebook access tokens have a lifetime of about two hours. For longer lived web apps, especially server side, need to generate long lived tokens. Long lived tokens generally lasts about 60 days.

UE has a capability to refresh facebook tokens. After adding connection using "apiv2.unificationengine.com/v2/connection/add"; api call, then you should call "apiv2.unificationengine.com/v2/connection/refresh"; api to make the short lived token to long lived.

AMT.in
  • 391
  • 1
  • 5
  • yes we tried that also. Sometimes it gives error invalid token same as send message. And sometimes it give 200 success code but does not return uri with success info. What could be the possible reason. – Always_a_learner Jan 07 '17 at 16:25
  • It seems that the uri won't be returned in response, but UE just refreshes the token and returns the status. – AMT.in Jan 09 '17 at 05:28