前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >how to create authentication string for each twitter API call

how to create authentication string for each twitter API call

作者头像
Jerry Wang
发布2019-07-03 16:35:47
4350
发布2019-07-03 16:35:47
举报

Created by Jerry Wang on Aug 16, 2014

The following information must be available to populate authentication string for current twitter API call:

clipboard2
clipboard2

Step1

generate the intermediate authentication string by concatenate the technical name of each field and its value into single line by “%3D”, then concatenate each single line into the intermediate string by “%26”.

Step2

generate the base authentication string via the following logic:

The string populated in this step should be:

<current http request name>&<current twitter API url>&<intermediate authentication string generated in step1 >

A sample base authentication string looks like as below:

GET&http%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fmentions_timeline.json&oauth_consumer_key%3DdbsDIeSbFjl7J5UuXXBb8g%26oauth_nonce%3D3DC99B81145ED0726C20207FB8B6A0A8%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1365573543%26oauth_token%3D1322278441-fhsyXxAY3yRLCgJxxQwN7IoRWr73CiJ2ogA08s9%26oauth_version%3D1.0

Step3

Generate authentication string for field “oauth_signature” using HMAC-SHA1 algorithm.

The input parameters for the generation in this step are:

  1. Encryption key: consists of consumer secret and token secret combined with “&”.
  2. Base authentication string generated from step2.

For detail how to use HMAC-SHA1 algorithm to generate authentication string, please refer to attached sample code.

Step4

During this step value for all seven fields listed in table1 should be available.

Then the following steps must be done to generate the final authentication string:

  1. Concatenate field name with field value by “=”.
  2. Surround field value with “.
  3. Concatenate each name-value pair with “, “.
  4. Add header “OAuth “ into the beginning of string.

You can use the following sample authentication string as a reference.

OAuth oauth_consumer_key=“ajaTgSs6QlXni558PjNg”, oauth_token=“1003016971-gRDT3Db0fcnaEvnldIGqrRH6P1Bsu6qXAUfs19b”, oauth_timestamp=“1365576176”, oauth_nonce=“C505BDC4FF6B4804A5A0F17EDD5D48EF”, oauth_version=“1.0”, oauth_signature_method=“HMAC-SHA1”, oauth_signature=“Yj%2BA3IrvgzWpNImngMV1gvnnbiU%3D”

For more detail information about OAuth protocol please refer to following links:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年07月02日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Created by Jerry Wang on Aug 16, 2014
  • Step1
  • Step2
  • Step3
  • Step4
相关产品与服务
访问管理
访问管理(Cloud Access Management,CAM)可以帮助您安全、便捷地管理对腾讯云服务和资源的访问。您可以使用CAM创建子用户、用户组和角色,并通过策略控制其访问范围。CAM支持用户和角色SSO能力,您可以根据具体管理场景针对性设置企业内用户和腾讯云的互通能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档