1

I am using #unificationengine API to send message on facebook. Details I have given while registering my APP on facebook:

  1. site url : http://localhost:3000

  2. Email adress and other required details

In unificationengine API I have used all the curls mentioned in their documentation step by step as follows: 1. Created user using API key and Secret 2. Added connection 3. test connection 4. Refresh connection 5. Send message

All 4 gave 200 success code but send message gives 403 fobidden error.

The curl I am using for this is as below:

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

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

                            ),
                        ),
                    ),

                )
            );



    $ch = curl_init('https://apiv2.unificationengine.com/v2/message/send');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_USERPWD,'3f43c37b-a066-4cc4-a3be-33faf72d6a21:2722fc72d-5d347-4a3a-a82b-0c1ss51aafb4');
    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 trying to figure this. But no success.

Again I like to mention that I am using this on localhost, could that be the reason for forbidden error? If so then facebook graph api from which we get access token should also give such error.

Earlier I have posted this question, here also I didn't find right solution. I added Curl options that is mentioned in comment of my question there but it didn't changed the things.

Any help would be highly appreciated.

Error Message:

{\"Status\":{\"facebook\":{\"status\":403,\"info\":\"Forbidden: \"}},\"URIs\":[]}

UPDATE Below is the json I get when I run me/permissions in facebook graph API explorer:

{
  "data": [
    {
      "permission": "user_birthday",
      "status": "granted"
    },
    {
      "permission": "user_about_me",
      "status": "granted"
    },
    {
      "permission": "user_status",
      "status": "granted"
    },
    {
      "permission": "user_posts",
      "status": "granted"
    },
    {
      "permission": "email",
      "status": "granted"
    },
    {
      "permission": "manage_pages",
      "status": "granted"
    },
    {
      "permission": "publish_actions",
      "status": "granted"
    },
    {
      "permission": "public_profile",
      "status": "granted"
    }
  ]
}
Community
  • 1
  • 1
Always_a_learner
  • 4,585
  • 13
  • 63
  • 112

2 Answers2

1

Can you please confirm if the "Connector" name that you have given is correct?

While I tried your sample code that you provided, I could sent the message to facebook via UE.

Can you please provide the exact error message that is returned while you execute the command?

AMT.in
  • 391
  • 1
  • 5
  • Connector name must be correct as I am using facebook connector and this is name given in scheme to used in API. this is the error message I am getting : {\"Status\":{\"facebook\":{\"status\":403,\"info\":\"Forbidden: \"}},\"URIs\":[]} – Always_a_learner Jan 09 '17 at 12:21
  • 1
    I think it is because of the "User Data Permissions" that you have granted while the access token was generated. You can grant the necessary "User Data Permissions" in graph explorer when a token is generated. – AMT.in Jan 10 '17 at 11:28
  • I have printed permissions using facebook graph api explorer me/permissions and I am have these permissions: manage_pages,publish_actions,user_posts,read_stream,user_onl‌​ine_presence,offline‌​_access,publish_stre‌​am – Always_a_learner Jan 10 '17 at 12:30
  • What other permissions do I need to assign? And how I can do that? can you please guide me with this? Thanks for your support!! – Always_a_learner Jan 10 '17 at 12:33
  • I have run me/permissions and I have updated my question and added json which I got in response. – Always_a_learner Jan 10 '17 at 12:43
  • 1
    With the same set of permissions I could sent message from UE using your test script. Can you just grant "publish_actions" and "user_posts" and try to send a message and check whats message does it return. Basically we need just publish_actions and user_posts to get an access token for posting to user wall – AMT.in Jan 11 '17 at 07:38
1

I have resolved this problem:

public function facebookSharing($access_token) {
        $app = new UEApp(env('UNIFICATION_APP_KEY'), env('UNIFICATION_APP_SECRATE'));
        $user = new UEUser('unification_userkey', 'unification_usersecret');
        $connection = $user->add_connection('FACEBOOK', "facebook", $access_token);
        $options = array(
            "receivers" => array(
                array(
                    "name"=> "Me"
                )
            ),
            "message"=>array(
                "subject"=>'testing',
                "body"=> 'description',
                "image"=> 'use any image url',
                "link"=>array(
                    "uri"=> 'any web site url',
                    "description"=> "",
                    "title"=>"Title"
                )
            )
        );
        $uris = $connection->send_message($options);
    }

Please use your keys like facebook accesstoken UNIFICATION_APP_KEY (its your unification keys) UNIFICATION_APP_SECRATE (its your unification keys)

If this will not work then please let me know.

Kuldeep Raj
  • 791
  • 1
  • 7
  • 29