首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法覆盖CONSUMER_KEY和CONSUMER_SECRET?

有没有办法覆盖CONSUMER_KEY和CONSUMER_SECRET?
EN

Stack Overflow用户
提问于 2015-12-08 10:35:52
回答 1查看 198关注 0票数 0

我用的是laravel和thujohn/twitter包。但我希望无论什么时候注册的任何用户都会提供CONSUMER_KEY和CONSUMER_SECRET,我们将利用这些细节发布推特、收藏推特等等。

但是在thujohn/twitter包中,CONSUMER_KEY和CONSUMER_SECRET是一次性设置的,这将用于所有用户,我想使用每个注册用户都会使用自己的消费者详细信息。

任何一个人都知道同样的解决方案

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-08 10:54:35

查看源代码,您可以使用reconfigure方法:

代码语言:javascript
复制
/**
 * 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;
}

因此,您可以传递一个数组,其中包含您想要的内容:

代码语言:javascript
复制
Twitter::reconfigure([
    'consumer_key'               => '',
    'consumer_secret'            => '',
    'token'                      => '',
    'secret'                     => '',
]);

然后将此信任传递给父库,它是另一个名为tmhOAuth的库,这是该库的代码:

代码语言:javascript
复制
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'              => "\r\n",
            '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
    );
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34153633

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档