YouTube API V3 404 error on getting my subscriptions - php

I have created new YouTube account for test purposes. I got an accessToken for this account and tried to get my own subscriptions via YouTubeAPI.
I use Google APIs Client Library for PHP.
$data = $service->subscriptions->listSubscriptions('snippet', ['mine' => 'true']);
I get an error:
"domain": "youtube.subscription",
"reason": "subscriberNotFound",
"message": "The subscriber identified with the request cannot be found.",
"locationType": "parameter",
"location": "channelId"
"code": 404,
"message": "The subscriber identified with the request cannot be found."
I tried to change the YouTube account, and I got a successful result on my old account. But I want to get info on my new account.
What the problem?

Related

Accessing google spreadsheet API restrictions in PHP issue

I've created a spreadsheet, which I managed to successfully update with some data using the google api library and by creating a service accounts credentials from Google console -> Api & Services -> Credentials.
My problem is to try to restrict the access of the spreadsheet file. If don't allow to be publicly available for everyone with Editor roles, it will not work. I m getting this message:
{
"error": {
"code": 403,
"message": "The caller does not have permission",
"errors": [
{
"message": "The caller does not have permission",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}
If I allow for everyone to access my spreadsheet, like in the image below , it will work .
I am also running my script, which updates the spreadsheet via a cronjob. Also this is the code where I do the auth part and I'm using the data from my Service Contract:
$client = new Google_Client();
$client->setApplicationName('Google Sheets and PHP');
$configuration = '{
"type": "'.$apiConfig['keyFile']['type'].'",
"project_id": "'.$apiConfig['projectId'].'",
"private_key_id": "'.$apiConfig['keyFile']['private_key_id'].'",
"private_key": "'.$key.'",
"client_email": "'.$apiConfig['keyFile']['client_email'].'",
"client_id": "'.$apiConfig['keyFile']['client_id'].'",
"auth_uri": "'.$apiConfig['keyFile']['auth_uri'].'",
"token_uri": "'.$apiConfig['keyFile']['token_uri'].'",
"auth_provider_x509_cert_url": "'.$apiConfig['keyFile']['auth_provider_x509_cert_url'].'",
"client_x509_cert_url": "'.$apiConfig['keyFile']['client_x509_cert_url'].'"
}';
$client->setAuthConfig(json_decode($configuration, true));
$client->setScopes([Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
return new Google_Service_Sheets($client);
Does anyone have any clue how can I restrict the access? and still have this work?
Thanks a lot for any suggestions
Finally I got it work by adding this email address :
To the Share with people and groups. See image from my post(question) .

Gmail API Returns 404 for a MessageId

So this is my process flow for sending a new email.
I send draftId from front end Gmail to back-end server, and then from draftId, I get messageId.
When I try to later get info on that messageId, the Gmail API Service returns:
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
I was able to research and look into message history API to see that for some reason, that sent message is marked as deletedMessages.
However, the message shows as in my Sent emails so it is clearly not deleted.
This appears to have started showing up recently as well.
Does anyone have any idea why this happens?

YouTube Content ID API with Service Account returns Forbidden error

I've created a service account for use with the YouTube Content ID API, I'm following the steps under Set up your service account on:
https://developers.google.com/youtube/partner/guides/oauth2_for_service_accounts
The steps seem to be a bit outdated, but I'm managed to create a service account and I've got the email address. I didn't know if I needed to assign a Role so I didn't.
I visited the Content ID users page and invited the service account user:
The problem is I get the error the request could not be completed, but when I refresh the page, the user appears to be added successfully.
Well, when I'm making requests using this service account, I'm getting forbidden errors. For example the below error is when I'm trying to get a list of claims.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
But some requests work, like listing/inserting labels, listing content owners.
All the permissions are assigned for the user so I'm not sure what the reason for the forbidden errors are.
Here's the PHP code:
$OAUTH2_KEY_FILE = 'key.json';
$client = new \Google_Client();
$client->setAuthConfig($OAUTH2_KEY_FILE);
$client->setScopes([\Google_Service_YouTubePartner::YOUTUBEPARTNER]);
$youtubePartner = new \Google_Service_YouTubePartner($client);
dd($youtubePartner->claims->listClaims([
'onBehalfOfContentOwner' => 'XXX'
]));

Seeking code example for OAuth 2.0 with Google Ad Exchange seller-API

First things first:
The goal is to pull reports from via ADX seller API.
I followed the tutorial, created a Project in the GDC, activated the adx-seller-API and added an OAuth 2.0 client ID just to make sure both types, "Web application" and "Other".
The code is easy enough, I got the google-api-php-client via composer and used the minimal example:
<?php
require_once 'vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfigFile('client_secrets.json');
$client->addScope('https://www.googleapis.com/auth/adexcange.seller');
$service = new Google_Service_AdExchangeSeller($client);
$result = $service->accounts->listAccounts();
print_r($result);
?>
However running the code only yields an exception:
Google_Service_Exception: { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Login Required" } } in [SNIP]\vendor\google\apiclient\src\Google\Http\REST.php on line 105
So basically 401: Login required
I also used both generated JSON for client_secrets.json, only the "other" one works.
If I use the Google API Explorer it works just fine, oddly the accountId that is talked of everywhere seems to be the DFP-ADX Publisher ID in case anyone is ever wondering.
I've no idea why this isn't working? Am I missing something important or doing something wrong?
In case it helps, I tried the same with Python, for some reason I get as far as to the authentication via browser, the adexchangeseller.dat is created and then it pops a 403: User does not have an Ad Exchange Seller account. which is hilarious considering it does and works via Google API Explorer.
Any help, even a push towards a decent tutorial is appreciated a lot of researching only led to dead ends.

PHP Google Play Subscription API

I am trying to get Google Play API subscription details using PHP and using following url to get purchase data :
https://www.googleapis.com/androidpublisher/v1/applications/[PACKAGE]/subscriptions/[SKU]/purchases/[PURCHASE_TOKEN]?access_token=[ACCESS_TOKEN]
I am getting the following error:
{
"error": {
"errors": [
{
"domain": "androidpublisher",
"reason": "developerDoesNotOwnApplication",
"message": "This developer account does not own the application."
}
],
"code": 401,
"message": "This developer account does not own the application."
}
}
Please help me sort out.
Just providing the URL does not help you get data of any application. How can you think so.? Isnt it insecure.? You have to get proper data by which you can at least prove ownership for the app..

Categories