YouTube Data API - 401 GoogleAccountCredential Invalid Credential - android

I am using YouTube Data API in my app, and for some reason, sometimes I get an error, when user tries to upload a video.
Here it is:
D/Test (28216): 401 Unauthorized
D/Test (28216): {
D/Test (28216): "code" : 401,
D/Test (28216): "errors" : [ {
D/Test (28216): "domain" : "global",
D/Test (28216): "location" : "Authorization",
D/Test (28216): "locationType" : "header",
D/Test (28216): "message" : "Invalid Credentials",
D/Test (28216): "reason" : "authError"
D/Test (28216): } ],
D/Test (28216): "message" : "Invalid Credentials"
D/Test (28216): }
I am authorizating user using GoogleAccountCredential like this:
List<String> ls = new ArrayList<>();
ls.add(YouTubeScopes.YOUTUBE_READONLY);
ls.add(YouTubeScopes.YOUTUBE_UPLOAD);
ls.add(YouTubeScopes.YOUTUBE_FORCE_SSL);
credential = GoogleAccountCredential.usingOAuth2(c, ls);
credential.setSelectedAccountName(name);
And I am not sure, what I'm doing wrong, because the error shows up very randomly, and only to some accounts, for e.g. on my phone the error never showed up, but on other people's devices yes.
Does anyone know how I can ensure this error won't show up, or at least how to fix the credentials after the error is shown?

Related

GoogleJsonResponseException: 403 Forbidden- Android

I am new to YouTube APIs. I have done create and fetch live events on YouTube. But I'm trying to start live events from my app I'm getting error:
Code:
fun startEvent(youtube: YouTube, broadcastId: String?) {
val transitionRequest = youtube.liveBroadcasts().transition(
"live", broadcastId, "status"
)
transitionRequest.key = context.getString(R.string.api_key)
transitionRequest.execute()
}
Error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
POST https://www.googleapis.com/youtube/v3/liveBroadcasts/transition?broadcastStatus=live&id=[BROADCAST_ID]&key=[API_KEY]&part=status
{
"code": 403,
"errors": [
{
"domain": "youtube.liveBroadcast",
"message": "Invalid transition",
"reason": "invalidTransition",
"extendedHelp": "https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/transition#params"
}
],
"message": "Invalid transition"
}

Google cloud translation api

Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Requests from this Android client application are blocked.",
"reason" : "forbidden"
} ],
"message" : "Requests from this Android client application are blocked.",
"status" : "PERMISSION_DENIED"

While Publsiing the private app get the following error

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"message" : "Invalid value at 'track_config.releases[0].status' (TYPE_ENUM), \"Completed\"",
"reason" : "invalid"
} ],
"message" : "Invalid value at 'track_config.releases[0].status' (TYPE_ENUM), \"Completed\"",
"status" : "INVALID_ARGUMENT"
}

Unable to create a WebToken for the Web App iframe using google-api-php-client

I am using the PHP library to use the Android Management API. I can update policies successfully. But I am unable to create a WebToken needed for the Web App iframe.
I have set a credential file.
I do
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope("https://www.googleapis.com/auth/androidmanagement");
$client->setApplicationName("MyAppName");
$androidmanagementService = new Google_Service_AndroidManagement($client);
Then I try to create a WebToken for the request:
$webTokens = $androidmanagementService->enterprises_webTokens;
$webToken = new Google_Service_AndroidManagement_WebToken();
My understanding is that only the ParentFrameUrl and Permissions are needed, everything else will be set in the answer:
$webToken->setPermissions(array("APPROVE_APPS"));
$webToken->setParentFrameUrl("http://37.71.157.174/mdm/");
But I tried also to set the other values:
//$webToken->setName("MyWebAppView");
//$webToken->setValue("98784");
Then I try to create the WebToken :
$webtoken = $webTokens->create("enterprises/entname", $webToken);
And I always get this Google_Service_Exception:
{ "error": { "code": 400, "message": "Invalid parameter: tokenSpec.parent", "errors": [ { "message": "Invalid parameter: tokenSpec.parent", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }
The full PHP exception is:
Uncaught Google_Service_Exception: { "error": { "code": 400, "message": "Invalid parameter: tokenSpec.parent", "errors": [ { "message": "Invalid parameter: tokenSpec.parent", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } } in /var/www/vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #0 /var/www/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 /var/www/vendor/google/apiclient/src/Google/Task/Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /var/www/vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run() #3 /var/www/vendor/google/apiclient/src/Google/Client.php(798): Google_Http_REST::execute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_ in /var/www/vendor/google/apiclient/src/Google/Http/REST.php on line 118
I have no idea what is wrong. But Everything before the WebToken part work for the other API call.
The URL of the parent frame must use the HTTPS scheme. I think that's the issue you're hitting.
This is mentioned in the documentation of the WebToken resource but it's true that the error message could be clearer.

Google plus for android bad access token

I been following Getting started and sign in to get access_token of user.
I do get an access token but when using it i am getting this error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
When I am going to apis-explorer and using they token it works just fine.
Any ideas what am I missing?
This is then URL I am trying.
https://www.googleapis.com/plus/v1/people/me?key={my_api_key}&access_token=my_access_token
These tokens have a 1 hour expiration period.

Categories

Resources