how to create authentication string for each twitter API call

简介: how to create authentication string for each twitter API call

Created by Jerry Wang on Aug 16, 2014

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



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:


&&

1

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:


Encryption key: consists of consumer secret and token secret combined with “&”.


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:


Concatenate field name with field value by “=”.


Surround field value with “.


Concatenate each name-value pair with “, “.


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:


相关文章
|
4月前
|
存储 JavaScript 前端开发
java9新特性之-String存储结构变更--集合工厂方法-- InputStream 加强--增强的 Stream API讲解
java9新特性之-String存储结构变更--集合工厂方法-- InputStream 加强--增强的 Stream API讲解
42 0
|
6月前
|
存储 Java API
API及String类和字符串相关使用方法
API及String类和字符串相关使用方法
|
7月前
|
存储 Java API
从零开始学习 Java:简单易懂的入门指南之API、String类(八)
从零开始学习 Java:简单易懂的入门指南之API、String类(八)
|
10月前
|
Java API
告别StringUtil:使用Java 全新String API优化你的代码
Java 编程语言的每一次重要更新,都引入了许多新功能和改进。 并且在String 类中引入了一些新的方法,能够更好地满足开发的需求,提高编程效率。
|
API
java202302java学习笔记第十五天-string中api查找
java202302java学习笔记第十五天-string中api查找
40 0
java202302java学习笔记第十五天-string中api查找
|
存储 JSON 缓存
Redis基本数据类型String基本API使用
Redis基本数据类型String基本API使用
|
存储 JSON 缓存
Redis基本数据类型String(字符串)基本API
Redis基本数据类型String(字符串)基本API
|
大数据 API Java
大数据基础之java常用API一(Object类、String类、StringBuilder类)
大数据基础之java常用API一(Object类、String类、StringBuilder类)
162 0
大数据基础之java常用API一(Object类、String类、StringBuilder类)
|
存储 Java API
【JAVA基础】String类常用API
1.String类常用API-遍历、替换、截取、分割操作 2.综合案例 2.模拟用户登录功能 3.手机号码屏蔽
【JAVA基础】String类常用API
|
Java 机器人 API
零基础学java---字符串(API,String,StringBuilder)
零基础学java---字符串(API,String,StringBuilder)
81 0