傻瓜式操作 第三方登入及分享
阿新 • • 發佈:2019-02-06
private class BaseUiListener implements IUiListener{
@Override
public void onComplete(Object response) {
Toast.makeText(MainActivity.this, "授權成功", Toast.LENGTH_SHORT).show();
Log.e(TAG, "response:" + response);
JSONObject obj = (JSONObject) response;
try {
String openID = obj.getString("openid");
String accessToken = obj.getString("access_token");
String expires = obj.getString("expires_in");
mTencent.setOpenId(openID);
mTencent.setAccessToken(accessToken,expires);
QQToken qqToken = mTencent.getQQToken();
mUserInfo = new UserInfo(getApplicationContext(),qqToken);
mUserInfo.getUserInfo(new IUiListener() {
@Override
public void onComplete(Object response) {
Log.e(TAG,"登入成功"+response.toString());
}
@Override
public void onError(UiError uiError) {
Log.e(TAG,"登入失敗"+uiError.toString());
}
@Override
public void onCancel() {
Log.e(TAG,"登入取消");
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(UiError uiError) {
Toast.makeText(MainActivity.this, "授權失敗", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(MainActivity.this, "授權取消", Toast.LENGTH_SHORT).show();
}
}
/**
* 在呼叫Login的Activity或者Fragment中重寫onActivityResult方法
* @param requestCode
* @param resultCode
* @param data
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == Constants.REQUEST_LOGIN){
Tencent.onActivityResultData(requestCode,resultCode,data,mIUiListener);
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onComplete(Object response) {
Toast.makeText(MainActivity.this, "授權成功", Toast.LENGTH_SHORT).show();
Log.e(TAG, "response:" + response);
JSONObject obj = (JSONObject) response;
try {
String openID = obj.getString("openid");
String accessToken = obj.getString("access_token");
String expires = obj.getString("expires_in");
mTencent.setOpenId(openID);
mTencent.setAccessToken(accessToken,expires);
QQToken qqToken = mTencent.getQQToken();
mUserInfo = new UserInfo(getApplicationContext(),qqToken);
mUserInfo.getUserInfo(new IUiListener() {
@Override
public void onComplete(Object response) {
Log.e(TAG,"登入成功"+response.toString());
}
@Override
public void onError(UiError uiError) {
Log.e(TAG,"登入失敗"+uiError.toString());
}
@Override
public void onCancel() {
Log.e(TAG,"登入取消");
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(UiError uiError) {
Toast.makeText(MainActivity.this, "授權失敗", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
Toast.makeText(MainActivity.this, "授權取消", Toast.LENGTH_SHORT).show();
}
}
/**
* 在呼叫Login的Activity或者Fragment中重寫onActivityResult方法
* @param requestCode
* @param resultCode
* @param data
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == Constants.REQUEST_LOGIN){
Tencent.onActivityResultData(requestCode,resultCode,data,mIUiListener);
}
super.onActivityResult(requestCode, resultCode, data);
}