forked from php-danfu.shenzhenbenwo.com

lefengyang
2025-09-10 9753a88eceb52a0f2e3084cf72f3474d2d7d7f1b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
============
OAuth plugin
============
 
Guzzle ships with an OAuth 1.0 plugin that can sign requests using a consumer key, consumer secret, OAuth token,
and OAuth secret. Here's an example showing how to send an authenticated request to the Twitter REST API:
 
.. code-block:: php
 
    use Guzzle\Http\Client;
    use Guzzle\Plugin\Oauth\OauthPlugin;
 
    $client = new Client('http://api.twitter.com/1');
    $oauth = new OauthPlugin(array(
        'consumer_key'    => 'my_key',
        'consumer_secret' => 'my_secret',
        'token'           => 'my_token',
        'token_secret'    => 'my_token_secret'
    ));
    $client->addSubscriber($oauth);
 
    $response = $client->get('statuses/public_timeline.json')->send();
 
If you need to use a custom signing method, you can pass a ``signature_method`` configuration option in the
constructor of the OAuth plugin. The ``signature_method`` option must be a callable variable that accepts a string to
sign and signing key and returns a signed string.
 
.. note::
 
    You can omit the ``token`` and ``token_secret`` options to use two-legged OAuth.