douxi4287 2015-12-08 10:35
浏览 78
已采纳

有没有办法覆盖CONSUMER_KEY和CONSUMER_SECRET

I am using laravel with the thujohn/twitter package. But i want whenever any use registered they will provide us CONSUMER_KEY and CONSUMER_SECRET and we will use that details to post the tweet,favorites tweet etc.

But in the thujohn/twitter package the CONSUMER_KEY and CONSUMER_SECRET is set one time and that will use for all users and i want to use each register user will use their own consumer details.

Any one know any solution on the same

  • 写回答

1条回答 默认 最新

  • drxm5014 2015-12-08 10:54
    关注

    Looking at the source code you have the reconfigure method:

    /**
     * Set new config values for the OAuth class like different tokens.
     *
     * @param Array $config An array containing the values that should be overwritten.
     *
     * @return void
     */
    public function reconfig($config)
    {
        // The consumer key and secret must always be included when reconfiguring
        $config = array_merge($this->parent_config, $config);
        parent::reconfigure($config);
        return $this;
    }
    

    So you can pass an array with the configs you want:

    Twitter::reconfigure([
        'consumer_key'               => '',
        'consumer_secret'            => '',
        'token'                      => '',
        'secret'                     => '',
    ]);
    

    This configs will then be passed to the parent which is another library called tmhOAuth here's the code for that:

    public function reconfigure($config=array()) {
        // default configuration options
        $this->config = array_merge(
            array(
                // leave 'user_agent' blank for default, otherwise set this to
                // something that clearly identifies your app
                'user_agent'                 => '',
                'host'                       => 'api.twitter.com',
                'method'                     => 'GET',
                'consumer_key'               => '',
                'consumer_secret'            => '',
                'token'                      => '',
                'secret'                     => '',
                // OAuth2 bearer token. This should already be URL encoded
                'bearer'                     => '',
                // oauth signing variables that are not dynamic
                'oauth_version'              => '1.0',
                'oauth_signature_method'     => 'HMAC-SHA1',
                // you probably don't want to change any of these curl values
                'curl_http_version'          => CURL_HTTP_VERSION_1_1,
                'curl_connecttimeout'        => 30,
                'curl_timeout'               => 10,
                // for security this should always be set to 2.
                'curl_ssl_verifyhost'        => 2,
                // for security this should always be set to true.
                'curl_ssl_verifypeer'        => true,
                // for security this should always be set to true.
                'use_ssl'                    => true,
                // you can get the latest cacert.pem from here http://curl.haxx.se/ca/cacert.pem
                // if you're getting HTTP 0 responses, check cacert.pem exists and is readable
                // without it curl won't be able to create an SSL connection
                'curl_cainfo'                => __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem',
                'curl_capath'                => __DIR__,
                // in some cases (very very odd ones) the SSL version must be set manually.
                // unless you know why your are changing this, you should leave it as false
                // to allow PHP to determine the value for this setting itself.
                'curl_sslversion'            => false,
                'curl_followlocation'        => false, // whether to follow redirects or not
                // support for proxy servers
                'curl_proxy'                 => false, // really you don't want to use this if you are using streaming
                'curl_proxyuserpwd'          => false, // format username:password for proxy, if required
                'curl_encoding'              => '',    // leave blank for all supported formats, else use gzip, deflate, identity etc
                // streaming API configuration
                'is_streaming'               => false,
                'streaming_eol'              => "
    ",
                'streaming_metrics_interval' => 10,
                // header or querystring. You should always use header!
                // this is just to help me debug other developers implementations
                'as_header'                  => true,
                'force_nonce'                => false, // used for checking signatures. leave as false for auto
                'force_timestamp'            => false, // used for checking signatures. leave as false for auto
            ),
            $config
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入