Unknow Error Android App

I am developing an Android app. I'm having a problem when I run the app and try to get a variable using the ParticleCloudSDK.init(this);. I get the error trying to do a getDevice.

ParticleDevice device =ParticleCloud.getDevice(getIntent().getStringExtra(ARG_DEVICEID));

If I hard code the DeviceID like
ParticleDevice device =ParticleCloud.getDevice(123456789xxxxxxxxx);
it works OK but if I try anything else than the hard coded deviceID I get the following error;

retrofit.retrofiterror: 403 forbidden

I made sure I was getting the deviceID OK before using it and it is valid.

Here is the routine I use:

private int getVariable(String svar,int xx) {
// Do network work on background thread
Async.executeAsync(ParticleCloudSDK.getCloud(), new Async.ApiWork<ParticleCloud, Object>() {

                        Object variable;
                        @Override
                        public Object callApi(@NonNull ParticleCloud ParticleCloud) throws ParticleCloudException, IOException {
                           ParticleDevice device =ParticleCloud.getDevice(getIntent().getStringExtra(ARG_DEVICEID)); 

                            try {
                                variable = device.getIntVariable(svar);

                            } catch (ParticleDevice.VariableDoesNotExistException e) {
                                Toaster.l(DeviceInfoAction.this, e.getMessage());
                                variable = "-1";
                            }
                            return variable;
                        }

Any help would be great thanks

The Particle Android SDK is deprecated and is not recommended for new apps. You should use the native Android APIs for making REST API calls to the Particle API instead of using the Particle SDK.

However, error 403 means your authentication token is not valid. Where is the code for setting it, and where did you obtain the token from? Or did you use the API to prompt the user?

Thanks Rick for getting back to me.

I'm a little confused since this does work if I hardcode my DeviceID.

I thought I needed to use the ParticleCloudSDK.init(this);

Can you point me to what I should be using.

Thanks

Oh, right. Definitely double-check that you're actually getting the correct Device ID when you don't hardcode it. You can also get a 403 if you attempt to retrieve the device information for a Device ID that is invalid or not in your account.

Though I'm curious how you even got it to compile. I didn't think that the Particle SDK compiled with any recent version of the Android SDK.

Just wanted to check to make sure Iam sing the right Android SDK. I am using a Boron and my android studio is using

AndroidX
compileSdkVersion 33
implementation 'io.particle:cloudsdk:1.0.1'//
implementation 'io.particle:devicesetup:0.7.3'

Also I use my own server for a user login with a Mysql db.

Question do I need to first login to particle before execution any SDK API?

I have made sure the DeviceID is correct. I have tried in a String, used the
intent.getStringExtra(ARG_DEVICEID) option and sent as a parameter in a function when I run the API's, but only way it works is if I hard-code like
ParticleDevice device = ParticleCloud.getDevice("e00fce68xxxxxxxxxxxx");

After some searching I finally figured out that I need to use a library called
"Retrofit" rather than the Particle SDK. Somehow I got start on using the Particle SDK and it worked, but is not meant for 3G devices.

If I'm wrong please let me know.

Thanks

Yes, that is correct. That's what I meant by:

You should use the native Android APIs for making REST API calls to the Particle API instead of using the Particle SDK.