oauth-plugin.rst 1.1 KB

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