Google Classroom API says it's disabled, but actually isn't - google-classroom

I have a problem using Google Classroom API for accessing the list of classrooms. I get the following error:
Google_Service_Exception: {
"error": {
"code": 403,
"message": "Google Classroom API (QA) has not been used in project XYZ before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/qa-classroom.sandbox.googleapis.com/overview?project=XYZ then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"errors": [
{
"message": "Google Classroom API (QA) has not been used in project XYZ before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/qa-classroom.sandbox.googleapis.com/overview?project=XYZ then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.",
"domain": "usageLimits",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com"
}
The problem is that it does not detect that the Classroom API is activated, because I'm pretty sure it is. If i go to the developer console and search for it, it shows up and it is activated, and it was activated more than 24h ago.
When I click on the link that the error shows me, it takes me to the developer console but the page is in blank, and if I open the Firefox console, I can see there is an error that says:
ERROR Error: ga Object: {"message":"Permission denied to get service [qa-classroom.sandbox.googleapis.com]\nHelp Token: MYTOKEN","permissionDenied":true,"errorExperience":2}`
I actually tried to delete the project and do it again with a new one, but I get the same result.
I use other APIs as Group Settings, Calendar, Contacts... and all work well, but Classroom doesn't.
Basically this is the code I'm trying to use:
$connection = new Google_Client();
$connection->setClientId($clientId);
$connection->setSubject($delegatedAdmin);
$connection->useApplicationDefaultCredentials();
$connection->setIncludeGrantedScopes(true);
$connection->addScope(Google_Service_Classroom::CLASSROOM_COURSES);
$classroomService = new Google_Service_Classroom($connection);
$params = array(
'pageSize' => 10,
'pageToken' => NULL
);
$response = $classroomService->courses->listCourses($params);
The scopes are correctly configured in Security > API Controls. And I repeat, every other API call from Group Settings, Calendar or Contacts, works just fine.
Does anyone have any idea of what I'm doing wrong?

The problem was that we were using an old version of the google library, and the root link of the API was deprecated.
I had to change
$this->rootUrl = 'https://prod-day0-classroom.sandbox.googleapis.com/';
to
$this->rootUrl = 'https://classroom.googleapis.com/';
Now it's working fine.

Related

Read Information for incoming slack webhooks via api

Following the steps for creating incoming webhooks via add to slack button. The final response will look like this:
{
"access_token": "xoxp-XXXXXXXX-XXXXXXXX-XXXXX",
"scope": "incoming-webhook,commands,bot",
"team_name": "Team Installing Your Hook",
"team_id": "XXXXXXXXXX",
"incoming_webhook": {
"url": "https://hooks.slack.com/TXXXXX/BXXXXX/XXXXXXXXXX",
"channel": "#channel-it-will-post-to",
"configuration_url": "https://teamname.slack.com/services/BXXXXX"
},
....
}
This provides access to team_name, channel the webhook will post to, and a url for configuration.
While this is working great and after initially storing the 'configuration' to my own webapp it displays correctly. But after a someone uses the 'configuration_url' link from the response these previous values like the channel could become obsolete. For example the webhook could be deleted from this link.
My Question is:
Is there a way to reflect this changes in my external app? As far as I can see there is no way to query information for 'incoming webhooks' via an api call from an external web application?
I also could not find any api calls that could change webhook configuration directly without using the provided link.
Its not possible to change the webhook configuration after it is created. The only possible change is that the workspace that installed your Slack app (which contains the webhook) is uninstalled.
If that happens the webhook will no longer work and you will get an error in response.
You can also get notified when you app is uninstalled by listening to the app_uninstalled event.
Or you can also test if your app and webhook is still valid by checking the token you received during the Add to Slack process. Just call the API method auth.test with that token. If it returns the following error than the webhook is no longer valid:
{
"ok": false,
"error": "invalid_auth"
}

Insufficient authentication scopes error using Google API

I set up Google SDK to use Google API with Application Default Credentials. For my local machine, created a credentials json file and set its path as GOOGLE_APPLICATION_CREDENTIALS as environment variable. This is worked as expected without a problem.
However, when the app is deployed to Google Cloud VM, it throws the following error:
[Google_Service_Exception]
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"errors": [
{
"message": "Request had insufficient authentication scopes.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
According to the documentation, the built-in service account should be associated with the virtual machine instance. To make it work, I tried to use credentials json file as I did on local machine (which worked fine) but it didn't work either.
To note, the error message is about scopes but not auth problem. What to do to make it work on Compute Engine VM instance?
To give client initialisation code:
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_Pubsub::PUBSUB);
Update
Now it is supported. You have to stop instance in order to change API scope.
https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#changeserviceaccountandscopes
Original answer
It turned out that I had to enable Cloud API access scope for the services on Google Cloud Console for VM instance details: https://console.cloud.google.com/compute/instances
Unfortunately, I couldn't changed it because Google Cloud doesn't support it for now. I had to start a new instance to enable a service API access.
https://googlecloudplatform.uservoice.com/forums/302595-compute-engine/suggestions/13101552-ability-to-change-cloud-api-access-scopes-on-launc
It is possible now. Your instance must be stopped and then it can have its scope list changed from the console in the edit vm page, or in the SDK by using :
gcloud compute instances stop [vmname]
gcloud beta compute instances set-scopes [vmname] --scopes="[scopes list]"
Just be aware that with the SDK way, the second command will reset with the scopes in the list. It is not currently available the ability to only append a new scope.

"400: Unsupported service specified, INVALID_ARGUMENT" from Google Cloud Logging API

I am trying to manually write a log entry using Google Cloud Logging API.
Before doing this via code, I am first trying to do it using the Google APIs Explorer. Here is a screen shot of the request I've built using this tool:
In projectsId I have the Google Project Id that I've copied from the
Google Developer Console.
Likewise for metadata.projectId.
In metadata.userId I have the Client Id of the same Service account that I'm using to authenticate (OAuth2) against the Google Logging API.
Google Logging API is enabled for the project.
The Service account belong to the project and has the "Can edit" permission.
I'm 99% sure that I've setup OAuth2 correctly for the request.
When I execute this request, I get the following response:
{
"error":
{
"code": 400,
"message": "Unsupported service specified",
"status": "INVALID_ARGUMENT"
}
}
Why? and how can I fix this?
The error message was actually telling me exactly which argument was invalid - The serviceName I supplied was bogus ("test").
As soon as I set the serviceName to be "compute.googleapis.com", the problem went away and I received a 200 status code indicating success.

Google API returning error accessNotConfigured

I recieve This a google error when using the url directly along with a newly created project (with no other projects listed) I continously get the below error....
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
],
"code": 403,
"message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
}
}
I know there have seen a few posts on this subject. and I have followed the instructions listed. I even created new project...
turned on fusion table in console (tried with both only fusion api on and nothering else & standard api
generated public key with the referers *
Consent screen filled out
fusion table Download allowed checked
shared with permission for "anyone with link" is selected
url = https://www.googleapis.com/fusiontables/v1/tables/105Otxh5ltQsKBr-ABqYJ8vBuB6E9Ped2MfXj3AZy/templates?&key=AIzaSyCr_wIc0aEHUG6Pl08kHDYLqWRB_PqZsE0
docid = 105Otxh5ltQsKBr-ABqYJ8vBuB6E9Ped2MfXj3AZy
key = AIzaSyCr_wIc0aEHUG6Pl08kHDYLqWRB_PqZsE0
Just what am I missing. I have the google php api client to use a service account.. but if I cant pull up the tables, query or anything via the base api url then i can move forward... untill then Im stuck. Thank in advance anyone!

Cannot add notification endpoints for Google APIs project

I have an application where I use OAuth2 to grab some info from a users spreadsheet in Google Drive. I have just completed the OAuth2 procedure, which I thought was the challenging part since there are no OAuth2 libraries for xquery, but now I am running into another problem.
I send a GET request to the Google Drive SDK, which I have turned ON in the Google API Console, and get the following output:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured"
}
],
"code": 403,
"message": "Access Not Configured"
}
}
I have found this question which seems to be the cause of my error :Google API returning Access Not Configured but I am unable to complete the solution to my problem which is to " Visit code.google.com/apis/console. First, make sure the service you want is enabled under "Services". Then go to "API Access" and specify your calling domains or IP addresses." When I try to add my domain to the notification endpoints, it doesn't do it.
In addition, I see that it says "Allows webhook notifications to be sent to external domains that are owned by the user. Google verifies that the user does in fact own each of the listed domains via Webmaster Tools" in the box where you add said endpoints. Since I am on an Amazon EC2 instance I am not sure that I will be able to do that. I really hope the fact that I am on an Amazon server is not stopping me from making my app.
Any help would be appreciated, thank you all.
You should enable Drive SDK and Drive API in the API console.

Resources