Forbidden error 403 in Unification Engine API whil

2019-08-02 19:25发布

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"
    }
  ]
}

2条回答
女痞
2楼-- · 2019-08-02 20:11

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.

查看更多
不美不萌又怎样
3楼-- · 2019-08-02 20:19

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?

查看更多
登录 后发表回答