How can I view json file using server key android? - android

I am new android devloper I do not know how to view json file using server key. If you know I need help. I have given some examples below.
#Headers({CACHE, AGENT})
#GET("api.php?get_ads")
Call<CallbackAds> getAds(
#Query("api_key") String api_key
);
api_key server key
public static final String SERVER_KEY = "WVVoU01HTklUVFpNZVRseVdWZDRNbUZYUm5sa1dGcHdURzFPZG1KVE9WVmFWM2hzWkcxc2VtRlhPWFZNTVZKb1lsZHNjMlJJV25WYVdHUjZXREpHZDJOSGVIQlpNa1l3WVZjNWRWTlhVbVpaTWpsMFRHeFNhR0pYYkhOa1NGbDFZbTFXTTJNelFtaGpSMVo1VEcxc2RWcEhiR2c9";
//your Rest API Key obtained from the admin panel
public static final String REST_API_KEY = "cda11Uib7PLEA8pjKehSVfY0vdHsXI269J3MlqcGatWZBmxOgR";

Related

Azure BLOB storage REST API - using ADAL access token returns 403 and 404 errors

I created an App Registration in Azure Active Directory and added the API permission to access Azure storage.
I also created a user and app role assignment as follows:
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $servicePrincipal.ObjectId -Id ([Guid]::Empty)
I gave the user the Storage Blob Data Contributor role in Azure portal. I then got an access token from this method:
public void acquireToken(android.app.Activity activity,
String resource,
String clientId,
#Nullable String redirectUri,
#Nullable String loginHint,
#NonNull com.microsoft.aad.adal.AuthenticationCallback<com.microsoft.aad.adal.AuthenticationResult> callback)
The clientId is the app with the permission to access storage. The redirect URI is the one I set for the app in the portal. I've tried two resource IDs. I send that token up as an Authentication: Bearer header.
It returns the error "Audience validation failed. Audience did not match" if the resource ID I pass to acquireToken is "https://<>.blob.core.windows.net/"
It returns the error "The specified container does not exist" if the resource ID is "https://storage.azure.com/".
I'm using Retrofit to perform the PUT operation.
public static final String CONTENT_TYPE_TEXT_PLAIN_HEADER = "Content-Type: text/plain; charset=UTF-8";
public static final String X_MS_VERSION = "x-ms-version: 2017-11-09";
public static final String X_MS_DATE = "x-ms-date";
public static final String X_MS_BLOB_CONTENT = "x-ms-blob-content-disposition: attachment; filename=\"fname.ext\"";
public static final String X_MS_BLOB_TYPE = "x-ms-blob-type: BlockBlob";
public static final String X_MS_META_M1 = "x-ms-meta-m1: v1";
public static final String X_MS_META_M2 = "x-ms-meta-m2: v2";
#Headers({CONTENT_TYPE_TEXT_PLAIN_HEADER,
X_MS_VERSION,
X_MS_BLOB_CONTENT,
X_MS_BLOB_TYPE,
X_MS_META_M1, X_MS_META_M2})
#PUT("/blob1")
Call<Void> putBlob(#Header(AUTHORIZATION) String bearerToken,
#Header(X_MS_DATE) String date,
#Body String putBody);
It returns the error "Audience validation failed. Audience did not match" if the resource ID I pass to acquireToken is https://<>.blob.core.windows.net/
Remove that trailing slash from https://<>.blob.core.windows.net/, it should now match what Azure AD expects for audience.
From https://learn.microsoft.com/en-us/azure/storage/common/storage-auth-aad-app#azure-storage-resource-id -
Azure Storage resource ID
An Azure AD resource ID indicates the audience for which a token that is issued can be used to provide access to an Azure resource. In the case of Azure Storage, the resource ID may be specific to a single storage account, or it may apply to any storage account. The following table describes the values that you can provide for the resource ID:
https://<account>.blob.core.windows.net

OneDrive Android SDK Navigate Available Sites

I'm trying to create a list of all current sites a user can access within their tenant and display it so the user can later select what site to upload files to. I'm using the OneDrive for Android SDK.
client.get()
.getDrive()
.getItems(root)
.getChildren()
.byId(name)
.getContent()
.buildRequest()
.put(contents, callback);
This code currently uploads a file to root, which is an id obtained from
client.get()
.getDrive()
.getRoot()
.buildRequest()
This obtains the root folder of my onedrive presumably using https://{tenant}-my.sharepoint.com/_api/v2.0/me. If I upload a file to root, the file is placed in the root directory of my OneDrive. I want to upload the file to a site "Test" I created instead of my root drive.
How would I go about finding and selecting a different site to upload my file to?
I ended up using Microsoft Graph SDK to solve my problem.
Found the relevant MSGraph API endpoint that returns all user sites using Microsoft Graph Explorer:
https://graph.microsoft.com/v1.0/sites?search=
Create classes to deserialize JSON:
public class Site {
#SerializedName("createdDateTime")
private String createdDateTime;
#SerializedName("id")
private String id;
#SerializedName("lastModifiedDateTime")
private String lastModifiedDateTime;
#SerializedName("name")
private String name;
#SerializedName("webUrl")
private String webUrl;
#SerializedName("displayName")
private String displayName;
}
public class Sites {
#SerializedName("value")
private ArrayList<Site> sites;
}
And create a custom request using BaseRequest from MSGraph SDK that deserializes the returned JSON:
public class CustomRequest extends BaseRequest {
public CustomRequest(final String requestUrl, final IBaseClient client, final java.util.List<Option> requestOptions) {
super(requestUrl, client, requestOptions, JsonElement.class);
}
public Sites getSites() throws ClientException {
Gson gson = new Gson();
JsonElement re = send(HttpMethod.GET, null);
Sites sites = gson.fromJson(re, Sites.class);
return sites;
}
Calling getSites method with AsyncTask and the necessary parameters returns a collection of Site objects with the sites the signed in user can access.
I leave this question unanswered in hopes it's actually possible to do this with the OneDrive SDK.

MobileHub where to store API keys

I am building an app based on the mobile hub sample app. The sample-app has the API keys stored in a class file AWSconfiguration:
public class AWSConfiguration {
// AWS MobileHub user agent string
public static final String AWS_MOBILEHUB_USER_AGENT =
"MobileHub ********* aws-my-sample-app-android-v0.16";
// AMAZON COGNITO
public static final Regions AMAZON_COGNITO_REGION =
Regions.fromName("us-east-1");
public static String AMAZON_COGNITO_IDENTITY_POOL_ID = "us-east-************6";
// Google Client ID for Web application
public static String GOOGLE_CLIENT_ID ="";//"*********************.apps.googleusercontent.com";
public static final Regions AMAZON_DYNAMODB_REGION =
Regions.fromName("us-east-1");
public static String AMAZON_COGNITO_USER_POOL_ID = "************";
public static String AMAZON_COGNITO_USER_POOL_CLIENT_ID = "*************";
public static String AMAZON_COGNITO_USER_POOL_CLIENT_SECRET = "*************";
private static final AWSMobileHelperConfiguration helperConfiguration = new AWSMobileHelperConfiguration.Builder()
.withCognitoRegion(AMAZON_COGNITO_REGION)
.withCognitoIdentityPoolId(AMAZON_COGNITO_IDENTITY_POOL_ID)
.withCognitoUserPool(AMAZON_COGNITO_USER_POOL_ID,
AMAZON_COGNITO_USER_POOL_CLIENT_ID, AMAZON_COGNITO_USER_POOL_CLIENT_SECRET)
.build();
/**
* #return the configuration for AWSKit.
*/
public static AWSMobileHelperConfiguration getAWSMobileHelperConfiguration() {
return helperConfiguration;
}
}
It seems unsafe to store the client secret key this way. What are the risks?
I experiemnted with hiding the keys in JNI files but could not find the proper entry point in the activity to set the keys before they are called from the mobile helper.
Storing in clear text is generally a bad idea, as you guessed. You could use the android keystore, store it encrypted (the stronger the key, the better), obfuscate it with some unique identifier of your device, or access it via some API you control and secure. It's possible to use some other solution, or a combination of the above possibilities. The final decision comes down to you and what your app needs/abilities are, but there's a few ways to hide it.
SharedPreferences.Editor can be a solution.
Password or something like this are stored in SharedPreferences.

quickblox android sdk unauthorized error

I download the chat sample from quickblox and follow all the steps at http://quickblox.com/developers/5_Mins_Guide iam geting unauthorized error
i spending days for it for simple open groupchat feature in my app
please could some one help me.
splashActivity.java is
private static final String APP_ID = <my id>;
private static final String AUTH_KEY = <auth key>;
private static final String AUTH_SECRET = <secret key>;
//
private static final String USER_LOGIN = "vamsi";
private static final String USER_PASSWORD = "******";
You need to go to the QuickBlox Admin Panel, go to the users section and add a new user with the credentials that you will be using first.

unable to send a notification to myself

After I followed all the steps for the push notification sample app. I wasn't able to send a notifaction to myself. I could send a pushmessage from my PC to my phone, but when I use the button Send myself a Notification nothing happens.
I am using Android sdk
After starting the app I do see that my Device is Registerd
Here is my settings.java
package com.ganyo.pushtest;
/** Change these values to match your setup! */
public class Settings {
static final String UNASSIGNED_ORG_VALUE = "";
// Google Client Id from Google API Console
static final String GCM_SENDER_ID = "xxxxxxxxxxxxx";
// Notifier Name in App Services
static final String NOTIFIER = "androidDev";
static final String API_URL = "https://api.usergrid.com";
static final String ORG = "xxxxxxx";
static final String APP = "sandbox";
// set these if you want to use a user login
static final String USER = null;
static final String PASSWORD = null;
}
I'm not sure what the UNASSIGNED_ORG_VALUE should be.
Thx in advance.
No need to assign any value to UNASSIGNED_ORG_VALUE. It's only used to check that you've entered the other values.
Please check your Android logs as well as the Apigee Console to see what error messages might have been generated during your push attempt. This will help you debug the issue.
Finally, you could try providing your notifier name here in all lowercase. (Note: This shouldn't generally be necessary, but I've heard there may be a issue that affects notifier name resolution.)

Categories

Resources