Listing teamdrive in google drive sdk with service account - java

I am trying to list the team drives using service account (domain wide delegation is enabled), when i do so with just the "teamdrives().list()" i am getting a blank response.
{
"kind" : "drive#teamDriveList",
"teamDrives" : [ ]
}
If i use "teamdrives().list().setUseDomainAdminAccess(true).setQ("name='Test'")" or "teamdrives().list().setUseDomainAdminAccess(true)" i am getting below error.
400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"location" : "q",
"locationType" : "parameter",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"
}
Below is the code block,
InputStream in = new FileInputStream("client_secret.json");
new GoogleCredential();
GoogleCredential credential = GoogleCredential
.fromStream(in)
.createScoped(SCOPES);
Drive _service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
tdllist = _service.teamdrives().list().setUseDomainAdminAccess(true).setQ("name='Test'");
TeamDriveList _tdl = tdllist.execute();
Hoping someone will point what i am doing wrong or an efficient way to do this.
Thanks in advance.
Thanks and Regards
KKG
Update
After some research got to know that "teamdrives().list()" is listing the teamdrive that the user has access to, so i guess that part is working as it is suppose to. But the remaining is still a mystery.

Related

Precondition check failed

it is been a while I use Google Classroom API till now it went so well, but I want to use setScheduledTime method for the announcement but didn't work I am getting the following error
Classroom service = new Classroom.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
Classroom.Courses courses2 = service.courses();
Material a = new Material();
a.setDriveFile(pptx2);
List<Material> materialNames = new ArrayList<>();
materialNames.add(a);
Announcement announcement = new Announcement().setScheduledTime("2021-11-20T23:48:00Z").setText("New Announcement").setMaterials(materialNames);
courses2.announcements().create("426056383414", announcement).execute();
This is the error I'm getting
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Precondition check failed.",
"reason" : "failedPrecondition"
} ],
"message" : "Precondition check failed.",
"status" : "FAILED_PRECONDITION"
}
To schedule an announcement for a future timestamp, you need to set it's current state to DRAFT:
Announcement announcement = new Announcement()setState("DRAFT").setScheduledTime("2021-11-20T23:48:00Z").setText("New Announcement").setMaterials(materialNames);

How to retrieve the subscriber list from a channel on YouTube?

I am trying to retrieve a subscriber list from a channel that it is not mine. If I go to a channel on YouTube the subscriber list is visible to the public. When I try to use the API to retrieve the list:
YouTube.Subscriptions.List list = subscriptions.list("snippet, contentDetails");
list.setChannelId(channelID);
SubscriptionListResponse searchResponse = list.execute();
List<Subscription> searchResultList = searchResponse.getItems();
for(Subscription result : searchResultList){
SubscriptionSnippet snippet = result.getSnippet();
ResourceId resourceId = snippet.getResourceId();
String id = resourceId.getChannelId();
dbConnection.addYouTubeRelationship(channel, id);
}
I get the following error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.subscription",
"message" : "The requester is not allowed to access the requested subscriptions.",
"reason" : "subscriptionForbidden"
} ],
"message" : "The requester is not allowed to access the requested subscriptions."
}
I am using an API-key based identification. Please, let me know if and how I can obtain the subscription list from the channels on YouTube.
Thank you.

Can't call App Script function thru the REST api

I'm using Java API for calling the AppScript function on the spreadsheet
When I list deployments
List<Deployment> deployments = projects.deployments().list("XXX").execute().getDeployments();
I can see my deployments but the deployment.getFunctionSet() is NULL
So when I call
Operation op = service.scripts().run(
"XXX",
new ExecutionRequest().setDevMode(true).setFunction("exportJson")
).execute();
I get
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "Requested entity was not found.",
"reason" : "notFound"
} ],
"message" : "Requested entity was not found.",
"status" : "NOT_FOUND"
}
The question - how to call function from the google app script? )

Copy object in Google Cloud Storage

I'm using the Java client for Google Cloud Platform to copy an object from inside a bucket to a different place in the same bucket.
To do that I followed the instructions here, but I'm getting a GoogleJsonResponseException 404 Bad Request:
class com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Required",
"reason" : "required"
} ],
"message" : "Required"
}
This is my code:
GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("key.json"))
.createScoped(Collections.singleton(StorageScopes.CLOUD_PLATFORM));
storageClient = new Storage.Builder(httpTransport, jsonFactory, credential).build();
StorageObject newObject = new StorageObject();
newObject.setName(newName);
Storage.Objects.Copy request = storageClient.objects().copy(bucketName, objectName, bucketName, newName, newObject);
request.setDestinationPredefinedAcl("publicread");
request.execute();
So far this is the only operation that fails, upload, download, getLength and a few others work just fine.
Update:
I manage to make it work removing this line:
request.setDestinationPredefinedAcl("publicread");
Anyway I would like to know what's wrong since in the future I would like to be able to chose if the new object is public or private.
I had the exact error when trying to copy an object from one place to another. The solution is to set newObject as null:
Storage.Objects.Copy request = storageClient.objects().copy(bucketName, objectName, bucketName, newName, null);

how to compose a request google cloud storage (for parallel upload) using java

I'm trying to upload a file (500 MB) to the google cloud storage. (java)
I created a List of Soource objects and I need to add ObjectPreconditions , ifGenerationMatch () to each of the object in that list.
I don't understand how to use it.
the errors I got from google were not informative at all.
StorageObject metadata = new StorageObject()
.setContentType("text/plain");
List<SourceObjects> sourceObjects = new ArrayList<SourceObjects>();
for (int i = 0; i <= chunkNumber; i++) {
sourceObjects.add( new SourceObjects().setName(objectName + ".chunk" + i) );
}
ComposeRequest composeReq = new ComposeRequest()
.setSourceObjects(sourceObjects)
.setDestination(metadata);
storage.objects().compose(bucketName, fileName,composeReq).execute();
and this is the error:
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "Not Found",
"reason" : "notFound"
} ],
"message" : "Not Found"

Categories

Resources