403通过统一引擎API向Facebook连接器发送消息时,禁止错误 [英] 403 forbidden error while sending messages to facebook connector through Unification Engine API

查看:167
本文介绍了403通过统一引擎API向Facebook连接器发送消息时,禁止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用统一引擎#unificationengine API在Facebook上发布消息。
我遵循所有步骤并创建连接以使用连接器。所有的卷曲请求都可以正常工作,直到发送消息。
在创建用户的每个卷曲中,创建连接,连接刷新我正在获得



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



现在我想使用连接器在Facebook上发布消息。
以下是我的卷曲代码:

  $ post_msg = json_encode(
array(
'消息'=>
数组(
'recipients'=>
数组(
数组(
'name'=>'我',
'address'=>'https://graph.facebook.com/'.$request-> profile_id。'/ feed?access_token ='。$ request-> access_token。& message = Hello& method = post',
'Connector'=>'facebook'

),
),
'sender'=>
array('地址'=>'发件人地址'),
'subject'=>'Hello',
'parts'=>
array(
array(
'id'=> '1',
'contentType'=> 'binary',
'data'=> '嗨欢迎来到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);




//执行!
$ response = curl_exec($ ch);

//关闭连接,释放资源使用
curl_close($ ch);

//用你的回应做任何你想要的
var_dump($ response);



return ['label'=> $回应]。

我得到:


状态:403和信息:被禁止回复。


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



请说明为什么我收到此错误?



Refrence SO问题:


  1. SO问题1


  2. SO问题2


谢谢。



更新
我在curl请求中添加了这三个选项: ($ ch,CURLOPT_SSL_VERIFYPEER,0);


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

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


{\Status\:{\facebook\:{\status\:498,\info\ :\无效的令牌:
\}},\URIs\:[]}



解决方案

请按照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(
recipients=> array(
array(
name=>Me

),
message=>数组(
subject=>测试,
体=>‘描述’,
的图像=> '使用任何图像url',
link=>数组(
uri=>'任何网站url',
description=>,
title=>标题


);
$ uris = $ connection-> send_message($ options);
}


I am using unification engine #unificationengine API to post message on facebook. I followed all the steps and created connections to use connectors. All the curl requests are working fine till send message. In every curl from create user, create connection, connection refresh I am getting

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

And now I want to use the connector to post message on facebook. Below is my Curl code:

$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];

and I am getting:

status: 403 and info: forbidden in response.

I have tried everything available in documentation and on stack overflow or any other website. But hard luck.

Please suggest why I am getting this error?

Refrence SO Questions:

  1. SO question 1

  2. SO question 2

Thanks.

Update I added these three options in curl request:

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

and now I am getting 498, invalid access token error:

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

解决方案

please use this as per 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);
    }

这篇关于403通过统一引擎API向Facebook连接器发送消息时,禁止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆