com.vk.sdk.VKAccessToken Java Examples
The following examples show how to use
com.vk.sdk.VKAccessToken.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentProfile.java From uPods-android with Apache License 2.0 | 6 votes |
@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); } }
Example #2
Source File: LoginActivity.java From vk_music_android with GNU General Public License v3.0 | 6 votes |
@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); } }
Example #3
Source File: LoginMaster.java From uPods-android with Apache License 2.0 | 5 votes |
private void initVkontakte() { VKAccessTokenTracker vkAccessTokenTracker = new VKAccessTokenTracker() { @Override public void onVKAccessTokenChanged(VKAccessToken oldToken, VKAccessToken newToken) { if (newToken == null) { } } }; vkAccessTokenTracker.startTracking(); }
Example #4
Source File: LoginMaster.java From uPods-android with Apache License 2.0 | 5 votes |
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; }
Example #5
Source File: VkApplication.java From vk_music_android with GNU General Public License v3.0 | 5 votes |
@Override public void onVKAccessTokenChanged(@Nullable VKAccessToken oldToken, @Nullable VKAccessToken newToken) { if (newToken == null) { Intent intent = new Intent(getApplicationContext(), LoginActivity.class); startActivity(intent); } }
Example #6
Source File: VKHttpClient.java From cordova-social-vk with Apache License 2.0 | 5 votes |
/** * 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; }
Example #7
Source File: VKRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
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; }
Example #8
Source File: VKRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
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); }
Example #9
Source File: VKRequest.java From cordova-social-vk with Apache License 2.0 | 5 votes |
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; }