本文整理汇总了Java中com.vk.sdk.VKAccessToken类的典型用法代码示例。如果您正苦于以下问题:Java VKAccessToken类的具体用法?Java VKAccessToken怎么用?Java VKAccessToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VKAccessToken类属于com.vk.sdk包,在下文中一共展示了VKAccessToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mTwitterAuthClient.onActivityResult(requestCode, resultCode, data);
if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() {
@Override
public void onResult(VKAccessToken token) {
initUIAfterLogin();
}
@Override
public void onError(VKError error) {
}
})) {
super.onActivityResult(requestCode, resultCode, data);
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
示例2: onActivityResult
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data ) {
if( !VKSdk.onActivityResult( requestCode, resultCode, data, new VKCallback<VKAccessToken>() {
@Override
public void onResult( VKAccessToken res ) {
AIR.log( "AuthFunction::onActivityResult | VK_AUTH_SUCCESS" );
AIR.dispatchEvent( AIRVKEvent.VK_AUTH_SUCCESS, VKAccessTokenUtils.toJSON( res ) );
}
@Override
public void onError( VKError error ) {
AIR.log( "AuthFunction::onActivityResult | VK_AUTH_ERROR: " + error.errorMessage + " reason: " + error.errorReason );
AIR.dispatchEvent( AIRVKEvent.VK_AUTH_ERROR, (error.errorMessage == null) ? "Error - user denied access." : error.errorMessage );
}
} ) ) {
AIR.log( "AuthFunction::onActivityResult | no callback" );
}
AndroidActivityWrapper.GetAndroidActivityWrapper().removeActivityResultListener( this );
}
示例3: onActivityResult
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
@Override
protected void onActivityResult(final int requestCode, int resultCode, Intent data) {
if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() {
@Override
public void onResult(final VKAccessToken accessToken) {
createUserComponentAndLaunchMainActivity();
}
@Override
public void onError(VKError error) {
new AlertDialog.Builder(LoginActivity.this)
.setMessage("Login failed: " + error.errorReason)
.setPositiveButton(android.R.string.ok, null)
.show();
}
})) {
super.onActivityResult(requestCode, resultCode, data);
}
}
示例4: onActivityResult
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!VKSdk.onActivityResult(requestCode, resultCode, data, new VKCallback<VKAccessToken>() {
@Override
public void onResult(VKAccessToken res) {
Log.i(LOG_TAG, "VKAccessToken: " + res);
// User passed Authorization
loadUser("onActivityResult");
}
@Override
public void onError(VKError error) {
// User didn't pass Authorization
Log.e(LOG_TAG, "onActivityResult.onError: " + error);
}
})) {
super.onActivityResult(requestCode, resultCode, data);
}
}
示例5: onReceiveNewToken
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
@Override
public void onReceiveNewToken(VKAccessToken newToken) {
super.onReceiveNewToken(newToken);
newToken.saveTokenToSharedPreferences(getActivity(), "VK_ACCESS_TOKEN");
VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "photo_200"));
request.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
super.onComplete(response);
VKList<VKApiUserFull> vkList = (VKList<VKApiUserFull>) response.parsedModel;
VKApiUserFull user = vkList.get(0);
saveUserData(
user.first_name + " " + user.last_name,
user.photo_200
);
((BaseSocialActivity) getActivity()).setLoginStatus(true, Const.SocialNetworks.VK_ID);
moveToProfile();
}
});
Log.d(LOG_TAG, "New User Token received");
}
示例6: processCommonError
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
private boolean processCommonError(VKError error) {
if (error.errorCode == VKError.VK_API_ERROR) {
if (error.apiError.errorCode == 14) {
error.apiError.request = this;
this.mLoadingOperation = null;
VKSdk.instance().sdkListener().onCaptchaError(error.apiError);
return true;
} else if (error.apiError.errorCode == 16) {
VKAccessToken token = VKSdk.getAccessToken();
token.httpsRequired = true;
repeat();
return true;
} else if (error.apiError.errorCode == 17) {
Intent i = new Intent(VKUIHelper.getTopActivity(), VKOpenAuthActivity.class);
i.putExtra(VKOpenAuthActivity.VK_EXTRA_VALIDATION_URL, error.apiError.redirectUri);
i.putExtra(VKOpenAuthActivity.VK_EXTRA_VALIDATION_REQUEST, this.registerObject());
VKUIHelper.getTopActivity().startActivityForResult(i, VKSdk.VK_SDK_REQUEST_CODE);
return true;
}
}
return false;
}
示例7: processCommonError
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
private boolean processCommonError(VKError error) {
if (error.errorCode == VKError.VK_API_ERROR) {
if (error.apiError.errorCode == 14) {
error.apiError.request = this;
this.mLoadingOperation = null;
VKSdk.instance().sdkListener().onCaptchaError(error.apiError);
return true;
} else if (error.apiError.errorCode == 16) {
VKAccessToken token = VKSdk.getAccessToken();
token.httpsRequired = true;
repeat();
return true;
} else if (error.apiError.errorCode == 17) {
Intent i = new Intent(VKUIHelper.getTopActivity(), VKOpenAuthActivity.class);
i.putExtra(VKOpenAuthActivity.VK_EXTRA_VALIDATION_URL, error.apiError.redirectUri);
VKUIHelper.getTopActivity().startActivityForResult(i, VKSdk.VK_SDK_REQUEST_CODE);
return true;
}
}
return false;
}
示例8: onActivityResult
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
VKCallback<VKAccessToken> callback = new VKCallback<VKAccessToken>() {
@Override
public void onResult(VKAccessToken res) {
// User passed Authorization
startTestActivity();
}
@Override
public void onError(VKError error) {
// User didn't pass Authorization
}
};
if (!VKSdk.onActivityResult(requestCode, resultCode, data, callback)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
示例9: initVkontakte
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
private void initVkontakte() {
VKAccessTokenTracker vkAccessTokenTracker = new VKAccessTokenTracker() {
@Override
public void onVKAccessTokenChanged(VKAccessToken oldToken, VKAccessToken newToken) {
if (newToken == null) {
}
}
};
vkAccessTokenTracker.startTracking();
}
示例10: getToken
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
public String getToken() {
if (Prefs.getString(SyncMaster.GLOBAL_TOKEN, null) != null) {
return Prefs.getString(SyncMaster.GLOBAL_TOKEN, null);
} else if (AccessToken.getCurrentAccessToken() != null)
return AccessToken.getCurrentAccessToken().getToken();
else if (Twitter.getSessionManager().getActiveSession() != null) {
TwitterSession session = Twitter.getSessionManager().getActiveSession();
TwitterAuthToken authToken = session.getAuthToken();
return authToken.token;
} else
return VKAccessToken.currentToken().accessToken;
}
示例11: requestWithVkRequest
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
/**
* Prepares new "normal" request from VKRequest
*
* @param vkRequest Request, created for some method
* @return Prepared request for creating VKHttpOperation
*/
public static VKHTTPRequest requestWithVkRequest(@NonNull VKRequest vkRequest) {
VKAccessToken token = VKAccessToken.currentToken();
VKHTTPRequest result = new VKHTTPRequest(String.format(Locale.US, "http%s://api.vk.com/method/%s", vkRequest.secure || (token != null && token.httpsRequired) ? "s" : "", vkRequest.methodName));
result.headers = getDefaultHeaders();
result.setVkParameters(vkRequest.getPreparedParameters());
return result;
}
示例12: getPreparedParameters
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
public VKParameters getPreparedParameters() {
if (mPreparedParameters == null) {
mPreparedParameters = new VKParameters(mMethodParameters);
//Set current access token from SDK object
VKAccessToken token = VKAccessToken.currentToken();
if (token != null) {
mPreparedParameters.put(VKApiConst.ACCESS_TOKEN, token.accessToken);
if (token.httpsRequired) {
this.secure = true;
}
}
//Set actual version of API
mPreparedParameters.put(VKApiConst.VERSION, VKSdk.getApiVersion());
//Set preferred language for request
mPreparedParameters.put(VKApiConst.LANG, getLang());
if (this.secure) {
//If request is secure, we need all urls as https
mPreparedParameters.put(VKApiConst.HTTPS, "1");
}
if (token != null && token.secret != null) {
//If it not, generate signature of request
String sig = generateSig(token);
mPreparedParameters.put(VKApiConst.SIG, sig);
}
//From that moment you cannot modify parameters.
//Specially for http loading
}
return mPreparedParameters;
}
示例13: generateSig
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
private String generateSig(VKAccessToken token) {
//Read description here https://vk.com/dev/api_nohttps
//At first, we need key-value pairs in order of request
String queryString = VKStringJoiner.joinParams(mPreparedParameters);
//Then we generate "request string" /method/{METHOD_NAME}?{GET_PARAMS}{POST_PARAMS}
queryString = String.format(Locale.US, "/method/%s?%s", methodName, queryString);
return VKUtil.md5(queryString + token.secret);
}
示例14: processCommonError
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
private boolean processCommonError(final VKError error) {
//TODO: lock thread, if ui required, release then
if (error.errorCode == VKError.VK_API_ERROR) {
final VKError apiError = error.apiError;
VKSdk.notifySdkAboutApiError(apiError);
if (apiError.errorCode == 16) {
VKAccessToken token = VKAccessToken.currentToken();
if (token != null) {
token.httpsRequired = true;
token.save();
}
repeat();
return true;
} else if (shouldInterruptUI) {
apiError.request = this;
if (error.apiError.errorCode == 14) {
this.mLoadingOperation = null;
VKServiceActivity.interruptWithError(context, apiError, VKServiceActivity.VKServiceType.Captcha);
return true;
} else if (apiError.errorCode == 17) {
VKServiceActivity.interruptWithError(context, apiError, VKServiceActivity.VKServiceType.Validation);
return true;
}
}
}
return false;
}
示例15: toJSON
import com.vk.sdk.VKAccessToken; //导入依赖的package包/类
public static String toJSON( VKAccessToken token ) {
if( token.userId == null ) return null;
JSONObject json = new JSONObject();
addValueForKey( token.userId, "userId", json );
addValueForKey( token.accessToken, "accessToken", json );
addValueForKey( token.secret, "secret", json );
addValueForKey( token.email, "email", json );
addValueForKey( token.expiresIn, "expiresIn", json );
addValueForKey( token.created, "created", json );
addValueForKey( token.httpsRequired, "httpsRequired", json );
/* Loop through all permissions and see which one are part of this token */
List<String> allPermissions = VKScope.parseVkPermissionsFromInteger( Integer.MAX_VALUE ); // Get all permissions
JSONArray activePermissions = new JSONArray();
/* VKAcessToken's scope may be null, however, it's not
* accessible directly so we have to wrap it in try-catch block */
try {
for( String permission : allPermissions ) {
if( token.hasScope( permission ) ) {
activePermissions.put( permission );
}
}
} catch( Exception e ) {
// VKAccessToken's 'scope' is null, thus no permissions
}
addValueForKey( activePermissions.toString(), "permissions", json );
return json.toString();
}