Now many apps or websites support using QQ account to log in. This article demonstrates how to implement a third-party login for QQ, as well as access to the user's personal information after login.
1, Tencent Open Platform registration, and SDK configuration (this can be official to find)
2, login authorization, and obtain user information
(1) Click the "Log in and get user Information" button
(2) The program will automatically jump to QQ, display the login page (the page will show the required authorization)
(3) After the successful login will automatically return to the original app. In this sample we get the user information and print it out after the login is successful
Attached: Return parameter description
Parameter name |
Description |
Ret |
The return code. See the public Return code description #openapi V3.0 return code. |
Msg |
If error, returns an error message. |
Is_lost |
Determine if there is data loss. If the application does not use cache, you do not need to care about this parameter.
0 or no return: No data loss, can be cached.
1: Some data is missing or wrong, do not cache.
|
Nickname |
Nickname. |
Gender |
Gender. |
Country |
Country (when Pf=qzone, pengyou or Qplus return). |
Province |
Province (returns when Pf=qzone, Pengyou, or Qplus). |
City |
City (returned when Pf=qzone, Pengyou, or Qplus). |
Figureurl |
Avatar URL. See: Front page Specification #6. About the user avatar acquisition and size description. |
Openid |
The user QQ number converts the ID (when Pf=qplus is returned). |
Qq_level |
User QQ level (returns when Pf=qplus). |
Qq_vip_level |
Users QQ Membership level (when Pf=qplus return). |
Qplus_level |
User q+ level (returned when pf=qplus). |
Is_yellow_vip |
is the yellow diamond user (0: not; 1: YES).
(returns when Pf=qzone, Pengyou, or Qplus)
|
Is_yellow_year_vip |
is the annual fee Yellow drill user (0: not; 1: YES).
(returns when Pf=qzone, Pengyou, or Qplus)
|
Yellow_vip_level |
Yellow drill level, currently the highest level of yellow drill 8 (if it is yellow drill user to return this parameter).
(returns when Pf=qzone, Pengyou, or Qplus)
|
Is_yellow_high_vip |
Is the luxury version of the Yellow Drill user (0: not; 1: YES).
(returns when Pf=qzone, Pengyou, or Qplus)
|
Is_blue_vip |
is a Blue Diamond user (0: not; 1: YES).
(returns when Pf=qqgame or 3366)
|
Is_blue_year_vip |
Is the annual fee Blue Drill user (0: not; 1: YES).
(returns when Pf=qqgame or 3366)
|
Blue_vip_level |
Blue Drill level (This parameter is only returned if the user is a blue drill).
(returns when Pf=qqgame or 3366)
|
3366_level |
3366 the user's large rating.
(returns when pf=3366)
|
3366_level_name |
3366 User's rank name, such as small Yu Yu, small Youxian.
(returns when pf=3366)
|
3366_grow_level |
3366 the user's growth rating.
(returns when pf=3366)
|
3366_grow_value |
3366 the user's growth value.
(returns when pf=3366)
|
Is_super_blue_vip |
Whether it is a luxurious blue diamond.
(returns when Pf=qqgame or 3366)
|
(4) Sample code:
Import Uikit
Class Viewcontroller:uiviewcontroller, tencentsessiondelegate{
var _tencentoauth:tencentoauth!
Override Func Viewdidload () {
Super.viewdidload ()
_tencentoauth = Tencentoauth.init (appId: "1105212016", anddelegate:self)
}
Login button click
@IBAction func Login (sender:anyobject) {
Set Permissions List
Let permissions = ["Get_user_info", "Get_simple_userinfo"];
Landing
_tencentoauth.authorize (permissions)
}
Login Complete Call
Func Tencentdidlogin () {
If!_tencentoauth.accesstoken.isempty {
Print ("----------------------------------------")
Print ("Login succeeded!") ")
Print ("Openid:\ (_tencentoauth.openid)",
"Accesstoken:\ (_tencentoauth.accesstoken)",
"Expirationdate:\ (_tencentoauth.expirationdate)")
Print ("Start getting user information")
_tencentoauth.getuserinfo ()
}else {
Print ("Login failed!") No access to Accesstoken ")
}
}
/**
* Callback after failed login
*/
Func Tencentdidnotlogin (Cancelled:bool) {
If cancelled {
Print ("User cancels login!")
}else{
Print ("Login failed!")
}
}
/**
* The network has a problem callback when logged in
*/
Func tencentdidnotnetwork () {
Print ("No network, unable to log on!")
}
/**
* Get callback for user information
*/
Func Getuserinforesponse (response:apiresponse) {
Print ("----------------------------------------")
Print ("User data obtained successfully:")
Print (Response.jsonresponse)
}
Override Func didreceivememorywarning () {
Super.didreceivememorywarning ()
}
}
3, Exit Login
To exit login, revoke authorization. You only need to invoke the logout () method of the Tencentoauth object.
_tencentoauth.logout (self)