doutuo8800
2012-03-20 16:35 阅读 49

用oauth令牌签署twitter rest请求

I have an app using the twitter rest API. Everything is working fine but we're bumping into rate limits so we need to authenticate using oAuth. I have the oauth token and secret. It's not a consumer facing app and we will only need to authenticate using this token and secret.

My question is how to include the token and secret in the rest request to authenticate?

There's a plenty of documentation on how to obtain the token and secret but I can't find any on how to use them.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    duanbei6427 duanbei6427 2012-03-20 18:38

    Using the TwitterOAuth PHP library it is as simple as this:

    <?php
    require_once('twitteroauth/twitteroauth.php');
    require_once('config.php');
    
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
    
    $content = $connection->get('account/verify_credentials');
    

    There are several more example requests in the demo index.php.

    点赞 评论 复制链接分享
  • dpmopn8542 dpmopn8542 2012-03-20 16:38

    Twitter documentation links to a few PHP OAuth libraries that you can use to accomplish OAuth authentication.

    点赞 评论 复制链接分享

相关推荐