[IOS Weibo project, [iOS blog Project

Source: Internet
Author: User

[IOS Weibo project, [iOS blog Project
A. ConceptThe OAUTH Protocol provides a secure, open, and simple standard for user resource authorization. Unlike the previous authorization method, OAUTH does not allow a third party to access user account information (such as user name and password ), that is, a third party can apply for authorization to the user's resources without using the user name and password. Therefore, OAUTH is secure. OAuth is short for Open Authorization.B. Use step 3OAUTH authentication is implemented in three steps. The following three sentences can be summarized: 1. Obtain an unauthorized Request Token2. obtain the user-authorized Request Token3. use the authorized Request Token in exchange for the Access Token. I. xx Weibo ---> User microblog data 1. Become a developer of Sina (joining the development camp of Sina Weibo)
* Register a Weibo account and log on to the http://open.weibo.com
Account: xxxxxx
Password: xxxxxx
* Fill in the developer's personal information (such as name, birth date, and upload ID card)

2. Create an application
* Assume that the Application name is "xx Weibo"
* After the application is created, it enters the "Development" stage by default and is qualified for authorization.
* Application-related data
App Key: 3145626526 // unique ID of the App
App Secret: ee9de4d2431be061b22fe328332a1111
Redirect URI: http://www.baidu.com

3. the user authorizes "xx Weibo" Resources ---- OAuth 2.0
1> Get Unauthorized Request Token: displays the login page provided by the server provider.
* URL: https://api.weibo.com/oauth2/authorize
* Parameters
Client_id true string the AppKey assigned when applying for an application // you must know which application is authorized.
Redirect_uri true string authorization callback address // the page to jump to after successful authorization

2> get the authorized Request Token
* After the authorization is successful, the callback page is automatically displayed, for example
Http://www.baidu.com /? Code = eabdc03cc4cc51484111b1cfd9c4cd0b
// Sina concatenates a parameter after the callback page: Request Token after successful authorization

3> exchange an Access Token based on the authorized Request Token
* URL: https://api.weibo.com/oauth2/access_token
* Parameters
Client_id true string the AppKey allocated when the application is applied.
Client_secret true string the AppSecret allocated when the application is applied.
Grant_type true string request type, fill in authorization_code
Code true string the code value obtained by calling authorize.
Redirect_uri true string callback address, which must be consistent with the callback address in the registered application
* Returned results
{
"Access_token" = "2.00vWf4GEUSKa7D739148f7608SXA9B ";
"Expires_in" = 157679999;
& Quot; remind_in & quot; = 157679999;
Uid = 3758830533;
}
// Uid = user_id = ID of the current logon user = unique ID of the user

{
"Access_token" = "2.00vWf4GEUSKa7D739148f7608SXA9B ";
"Expires_in" = 157679999;
& Quot; remind_in & quot; = 157679999;
Uid = 3758830533;
}

* Access_token and uid
Access_token: After a user successfully authorizes an application, the corresponding access_token is obtained. The function is to allow an application to access data of one user.
Uid: one user corresponds to one uid, each of which has its own unique uid
Example:
Zhang San
Li Si

Application 1
Application 2

Michael Zhang successfully authorized application 1 and Application 2: 1 uid and 2 access_token.
Li Si authorized application 2 successfully: 1 uid and 1 access_token
The above operation: Two UIDs and three access_token are generated.

2. Common Errors During authorization:
1. invalid_request
1> no required request parameters are passed
2> incorrect Request Parameters
3> leave spaces in the middle of the URL

2. invalid_client
1> the value of client_id is incorrect (the AppKey is incorrect)

3. redirect_uri_mismatch
1> the callback address is incorrect.

Iii. Account authorization Note 1. If the application has not been reviewed by Sina, you can only access Weibo data of yourself or other 15 test accounts.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.