i want to use Google Cloud Storage for my image backend, my B4J Service would be handle the auth.
I have create a service account and have set the permissions to this account, to access the bucket.
How can i authenticate the B4J service to access the images?
I have a .json file with "project_id", "private_key_id", "private_key"...
Ohh, i see. that´s a problem for sure. Unfortunately i can´t help here.
I am using a serviceaccount on our website to sync our Calendar to Google Calendar using a php library from Google.
I don´t know the correct way to authenticate from java (non ui). I guess you need to build everything for a Google HTTP Client.
I tried to build one a few times but only had limited success so far.
public void Initialize(BA ba, String EventName) {
this.eventName = EventName.toLowerCase(BA.cul);
this.ba = ba;
Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
// The kind for the new entity
String kind = "Task";
// The name/ID for the new entity
String name = "sampletask1";
// The Cloud Datastore key for the new entity
Key taskKey = datastore.newKeyFactory().setKind(kind).newKey(name);
// Prepares the new entity
Entity task = Entity.newBuilder(taskKey)
.set("description", "Buy milk")
.build();
// Saves the entity
datastore.put(task);
ba.Log("Saved "+task.getKey().getName()+"/"+task.getString("description"));
//Retrieve entity
Entity retrieved = datastore.get(taskKey);
ba.Log("Retrieved "+taskKey.getName()+" / "+retrieved.getString("description"));
}
So, if all works (i do expect crashes ) you should get two lines in your log and a Buy milk task should be created in the Datastore.
But i expect it to crash at this stage of development.
javac 1.8.0_191
src\b4j\example\main.java:98: error: cannot access Datastorewrapper
public static de.donmanfred.Datastorewrapper _google = null;
^
bad class file: C:\Users\Schnattern\OneDrive\B4X Libs\Add B4J\googlecloudstorage.jar(de/donmanfred/Datastorewrapper.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
Amazon S3 was easier (but expensive), because there is IP whitelisting there.
i see. I am using OpenJava 11 in B4J.
But even if you would use the same Java, you would get stuck with it as it is missing some imports. I tried it yterday but did not get it working here too...
Additionally i started doing a wrap for the wrong component. You dont need the Datastore, you need the Storage. I switched to the storage but at the end i failed finding the right imports... The day ended and i stopped...
Will try to investivate but guess it needs some time.
GoogleOAuth2 class takes care of it. It uses the refresh token to get a new access token. The UI part where the user approves the service is only required once.
I have such a service running for months, downloading data from Google Sheet every few minutes.
GoogleOAuth2 class takes care of it. It uses the refresh token to get a new access token. The UI part where the user approves the service is only required once.
So I only need 1 time to create a token with the UI application. Then I can pak the code in the non-Ui and he updates then by itself?
Because, later i have 20+ VPS's, It should be done automatically