Taobao open platform SDK docking

http://blog.csdn.net/papalian/article/details/20550795

First you have to have a registered appkey and App Secret
 
The process is divided into three steps:  
Step 1: Obtain the authorization code Code through user authorization;  
Step 2: Use the Code obtained in the previous step and the application key (AppSecret) to exchange the Token through Https Post.  
Step 3: Get user Nick or other information
Step 4: Save session information
 
1. Obtaining the authorization code When the Code application requests to obtain user information, it first guides the user (Redirect) to the login authorization page https://oauth.taobao.com/authorize 

The parameters to be passed are: 


name
Is it necessary describe
response_type AND Here is a web application, this value is fixed as code
client_id AND That is, the Appkey when the application was created
redirects AND The callback address after login, (Note: This address must match the callback address when registering the application, the matching rule is: Note that the domain name matches exactly
state N This parameter is defined by the application. After the user authorizes, the authorization server will return this parameter intact.  
Note: The application can use the optional parameter state to record the current page location information of the user, so that after the user logs in and authorizes, the page can be called back to the user's previous location.

For example: https://oauth.taobao.com/authorize?response_type=code&client_id=12251541&redirect_uri=http://www.xx.org&state=1  

[attachment=335]  

After the user logs in, the user authorization page is displayed:  
[attachment=336]  

At this point, the user can choose to "authorize" or "cancel" (ie, do not agree to the authorization).  
If the user agrees to the authorization, it will jump to the callback address (redirect_uri) of the application, and at the same time, the application will obtain the authorization code code  
[attachment=337]  

If the user cancels the authorization or access error  
[attachment=338]  

Second, exchange the authorization code Code for the Token application After obtaining the authorization code, send Https Post to the authorization server. The authorization server verifies the validity of the authorization code and the AppSecret of the application. After the verification is passed, the authorization server returns the Access Token to the application.  



The parameters that need to be passed are: 


name
Is it necessary describe
grant_type AND Authorization type authorization_code or refresh_token
code AND The authorization code in the authorization request, that is, the code obtained in the first step
redirects AND The callback address after login, (Note: This address must match the callback address when registering the application, the matching rule is: Note that the domain name matches exactly
client_id AND Customer ID, i.e. appkey
client_secret AND Client secret, which is appsecret


The following is the java code to achieve authorization:  

Step 1:  
Set up the login entry on the website 
  1. <A class="g6" title=会员登录 
       href="https://oauth.taobao.com/authorize?client_id=12381144&response_type=code&state=1&redirect_uri=http://localhost:2011/WinTaobao/do.jsp" target="_blank"> 
       登录


第二步,在redirect网站接受登录后返回的code,并获得access_token

  1.  access_token就相当于sessionKey,后续调用其他接口可以直接使用 

 

三、使用淘宝api获取登陆的用户名,将此用户名设置到session中。

 

http://blog.csdn.net/jmdonghao/article/details/54317474

1.首先需要有一个淘宝账户,一般实名认证支付宝之后就可以入住开发者平台。 
2.首先确定自己要对接的接口在哪一个应用下面,因为需要下载对应应用的sdk用来调用。确定好是哪一个应用之后创建相对应的应用。 
这里写图片描述
3.创建好应用之后点击前面的sdk小图标会弹出sdk的下载页面,下载sdk保存到本地。在应用管理界面获取到appkey和appSrecet 
这里写图片描述
4.获取code 
获取code地址: 
response_type = code(必填) client_id = *(创建应用所对应的appkey) redirect_uri(创建应用写的回调地址) 
https://oauth.taobao.com/authorize?response_type=code&client_id=23580296&redirect_uri=http://www.baidu.com 
回调成功之后 
这里写图片描述 
5.获取access_token 
第一种通过代码获取

import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    import com.taobao.api.internal.util.WebUtils; //引用top sdk
     public class Access {
        public static void main(String[] args) {
          String url="https://oauth.taobao.com/token";
          Map<String,String> props=new HashMap<String,String>();
          props.put("grant_type","authorization_code");
    /*测试时,需把test参数换成自己应用对应的值*/
          props.put("code","F8qjHTLNqsDrmBAvWJFoVTID66409");
          props.put("client_id","23580296");
          props.put("client_secret","56bd3eef5b57bc793b1ca862c0655472");
          props.put("redirect_uri","http://www.baidu.com");
          props.put("view","web");
          String s="";
          try{s=WebUtils.doPost(url, props, 30000, 30000);
          System.out.println(s);
          }catch(IOException e){
              e.printStackTrace();}
        } }

回示例:

{ 
“taobao_user_nick”: “%E4%B8%AD%E5%9B%BD%E9%80%9F%E5%B0%94%E7%89%A9%E6%B5%81”, 
“re_expires_in”: 0, 
“expires_in”: 86400, 
“expire_time”: 1482909750088, 
“r1_expires_in”: 1800, 
“w2_valid”: 1482823350088, 
“w2_expires_in”: 0, 
“taobao_user_id”: “1065192055”, 
“w1_expires_in”: 1800, 
“r1_valid”: 1482825150088, 
“r2_valid”: 1482823350088, 
“w1_valid”: 1482825150088, 
“r2_expires_in”: 0, 
“token_type”: “Bearer”, 
“refresh_token”: “6200905426610ZZ4db9b00010469dba88bac4b493d2ca8b1065192055”, 
“refresh_token_valid_time”: 1482823350088, 
“access_token”: “6200b052e5b48ZZ0669262fb573a0c47a7bf0aa708639a01065192055” 
}

第二种通过工具获取,找到自己需要调用的api,然后点击上面的session获取工具,输入appkey然后登陆之后就可以按照引导获取了 
这里写图片描述

第一次对接淘宝平台,还有很多地方写的不清楚,望见谅。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326377141&siteId=291194637