通过统一引擎向 Facebook 连接器发送消息时出现 403 禁止错误 API

403 forbidden error while sending messages to facebook connector through Unification Engine API

我正在使用统一引擎 #unificationengine API 到 Facebook 上的 post 消息。 我按照所有步骤创建了连接以使用连接器。在发送消息之前,所有 curl 请求都工作正常。 在创建用户、创建连接、连接刷新的每个卷曲中,我得到

{'status':200,'info':'ok'}

现在我想使用连接器在 Facebook 上发送 post 消息。 下面是我的 Curl 代码:

$post_msg = json_encode(
        array(
            'message' =>
                array(
                    'receivers' =>
                        array(
                                array(
                                    'name'      => 'Me',
                                    'address'   =>'https://graph.facebook.com/'.$request->profile_id.'/feed?access_token='.$request->access_token.'&message=Hello&method=post',
                                    'Connector' => 'facebook'

                                ),
                        ),
                        'sender'    =>
                        array('address' => 'sender address'),
                        'subject'   => 'Hello',
                        'parts'     =>
                        array(
                                array(
                                    'id'          => '1',
                                    'contentType' => 'binary',
                                    '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_USERPWD, "0a7f4444-ae4445-45444-449-d9b7daa63984:8755b446-6726-444-b34545d-713643437560");
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, true); 
    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];

我得到:

status: 403 and info: forbidden in response.

我已经尝试了文档和堆栈溢出或任何其他网站上可用的所有内容。但是运气不好。

请告诉我为什么会出现此错误?

参考SO问题:

  1. SO question 2

谢谢。

更新 我在 curl 请求中添加了这三个选项:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, true); 

现在我收到 498,访问令牌无效错误:

"{\"Status\":{\"facebook\":{\"status\":498,\"info\":\"Invalid Token: \"}},\"URIs\":[] }

访问令牌可能已过期。请重新连接facebook连接或刷新连接。

Facebook 访问令牌的有效期约为两个小时。对于寿命更长的 Web 应用程序,尤其是服务器端,需要生成寿命更长的令牌。长寿命代币一般持续约 60 天。

UE 可以刷新 facebook 令牌。使用 "apiv2.unificationengine.com/v2/connection/add" 添加连接后; api调用,那么你应该调用"apiv2.unificationengine.com/v2/connection/refresh"; api 使短命令牌变为长命。

请按照php

使用
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);
    }