Google Adsense Management API: servingLimitExceeded with a few queries - adsense-api

We are receiving a servingLmitExceeded after making a few queries to the Adsense Management API for obtaining daily info about each app. We are connecting to 5 accounts.
What we do is first obtain a list of the apps of each account running a report of the last 30d:
$start_date = 'today-30d';
$end_date = 'today-1d';
$options = array(
'metric' => array('EARNINGS'),
'dimension' => array('APP_ID','APP_NAME'),
);
Then, for each app (like 36 in total divided in all the accounts) we run the following report:
$start_date = $today->format("Y-m-d");
$end_date = $today->format("Y-m-d");
$options = array(
'metric' => array('EARNINGS','AD_REQUESTS','AD_REQUESTS_COVERAGE','AD_REQUESTS_CTR','AD_REQUESTS_RPM','CLICKS','COST_PER_CLICK'),
'dimension' => array('APP_ID','COUNTRY_CODE'),
'filter' => array('APP_ID=#'.$app),
'sort' => '+APP_ID'
);
After a few apps, we receive the following error:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "servingLimitExceeded",
"message": "Serving Limit Exceeded"
}
],
"code": 403,
"message": "Serving Limit Exceeded"
}
}
We think that we aren't hiting any of the limits that appear here: https://developers.google.com/adsense/management/appendix/limits
We are doing less than 50 requests in total per day and our limits now are 100 queries per 100 second per user:
If we check the Google APIs console, it appears that the errors are being thrown by adsense.accounts.list
Does anybody knows how to avoid this problem?

A simple retry policy for the API call has worked for us.
It'll often go through if we retry 2-3 times with a 30s wait.

Related

Trying to write a calendar event using Microsoft Graph API issue

I'm trying to use the Microsoft Graph API to write calendar events within my company.
First of all let me give you a little bit of context.
I'm building a node API that uses Microsoft Graph to write calendar events, so I configured my application inside the Azure Active Directory with the following application permission
I granted administrator consent as you can see from the picture.
I was also able to get the access token using msal-node
const graphToken = async () => {
const azureConfig = {
auth: {
clientId: process.env.CLIENT_ID,
authority: `https://login.microsoftonline.com/${process.env.TENANT_ID}`,
clientSecret: process.env.CLIENT_SECRET,
},
}
const tokenRequest = {
scopes: [process.env.GRAPH_ENDPOINT + '/.default'],
}
const cca = new msal.ConfidentialClientApplication(azureConfig)
const authRespose = await cca.acquireTokenByClientCredential(tokenRequest)
if (authRespose) {
return authRespose.accessToken
}
return null
}
The only thing that sounds me a little odd, is the scope set to [process.env.GRAPH_ENDPOINT + '/.default'] I tried to change it ex. [process.env.GRAPH_ENDPOINT + '/Calendar.ReadWrite'] but it fires an excepion.
The next thing I'm able to do is retrive all calendars a user have right to write to, using the following Graph endpoint:
https://graph.microsoft.com/v1.0/users/user#example.com/calendars
Now the issue, when I try to do a POST request to write a calendar event for example
POST https://graph.microsoft.com/v1.0/users/{userId}/calendars/{calendarId}/events
{
"subject": "Test",
"body": {
"contentType": "HTML",
"content": "Test"
},
"start": {
"dateTime": "2022-11-09T16:00:00",
"timeZone": "Europe/Rome"
},
"end": {
"dateTime": "2022-11-09T17:00:00",
"timeZone": "Europe/Rome"
}
}
Note that calendarId is one of the id's from the previous call
(Not the default calendar of userId)
I got a 403 Forbidden with the following response
{
"error": {
"code": "ErrorAccessDenied",
"message": "Access is denied. Check credentials and try again."
}
}
I also decoded my token to see if I get some info on the root cause of the 403 error, I found this:
...
"roles": [
"Calendars.Read",
"User.Read.All",
"Calendars.ReadWrite"
],
...
It seems correct to me.
I don't get if it is a scope issue, an authentication issue or something I'm missing, can someone pinpoint me in the right direction?
Thanks in advance
Basically it was my fault.
I messed up with calendar permissions and my test user had a reviewer permission instead of an author one on the calendar I had to write to
once I was able to identify this issue and change the permission the call response was what expected.
I leave this answer as a reference for anyone that encounter this issue
Thanks anyway

Google Analytics RunReport return 7 PERMISSION_DENIED: User does not have sufficient permissions for this property

I want to run a google analytics report using runReport.
I have followed the instructions at https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries and made a copy of the code that uses json-credentials at https://github.com/googleapis/nodejs-analytics-data/blob/main/samples/quickstart_json_credentials.js
I have one Analytics Account with two Properties & Apps - DEV and STAGE.
In each of them I have created a service account with OWNER permissions. After that I created a key and downloaded the generated JSON-file.
I can test and run the API from the "Try this API" link at https://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1beta/properties/runReport for both my properties and it works well for both of them. (But then I use OAuth authentication of course).
However when I run the code using the JSON-credentials the DEV always work. The STAGE always fails. I have tried running the code both from my machine as well as from https://shell.cloud.google.com/ with the same result.
The failure message is:
7 PERMISSION_DENIED: User does not have sufficient permissions for this property. To learn more about Property ID, see https://developers.google.com/analytics/devguides/reporting/data/v1/property-id.
I have checked several times that the DEV and STAGE properties are correct and that the I use the JSON-credentials file associated with the correct property.
In STAGE, where calls always fail I have several times created new service accounts (with Basic->Owner credentials), created keys and downloaded JSON-credentials. But all with the same result. STAGE always fails.
I have compared the permissions for the service accounts in DEV and STAGE and they seems to be identical.
I have read and tried tips from other people with "permission denied" issues here at stack overflow but none that solves my issue.
Are there any authorization logs that I read from google console?
I'm kind of stuck now.
The code I run (properties and file name obfuscated):
"use strict";
function main(propertyId = "YOUR-GA4-PROPERTY-ID", credentialsJsonPath = "") {
propertyId = "27..DEV property";
credentialsJsonPath = "./DEVcredentials.json";
// propertyId = "27..STAGE property";
// credentialsJsonPath = "./STAGEcredentials.json";
const { BetaAnalyticsDataClient } = require("#google-analytics/data");
const analyticsDataClient = new BetaAnalyticsDataClient({
keyFilename: credentialsJsonPath,
});
async function runReport() {
const [response] = await analyticsDataClient.runReport({
property: `properties/${propertyId}`,
dateRanges: [
{
startDate: "2020-03-31",
endDate: "today",
},
],
dimensions: [
{
name: "country",
},
],
metrics: [
{
name: "activeUsers",
},
],
});
console.log("Report result:");
response.rows.forEach((row) => {
console.log(row.dimensionValues[0], row.metricValues[0]);
});
}
runReport();
}
process.on("unhandledRejection", (err) => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));
User does not have sufficient permissions for this property.
Means that the user who you have authenticated with does not have permissions to access that view. In this case we are talking about properties/${propertyId}
If you are using a service account make sure to grant it permissions at the account level not the view level.
Permissions need to be granted thorough the google analytics website in the admin section

I am Face two Issues using google Drive api : socket time out exception and user limit exceed

i face issues while connecting upload Picture to Google Drive . Sockect Time Out
my Intern was Good.
This was my Code to upload receipt in Google Drive
This Sockect Time out Exeception Error
In have Increased time out session. For Connect the Google drive
private HttpRequestInitializer setHttpTimeout(final HttpRequestInitializer requestInitializer) {
return new HttpRequestInitializer() {
#Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
httpRequest.setConnectTimeout(4 * 60000); // 3 minutes connect timeout
httpRequest.setReadTimeout(3 * 60000); // 3 minutes read timeout
}
};
}
Google Drive ---->Connected--> Return Code
private void handleSignInResult(Intent result) {
GoogleSignIn.getSignedInAccountFromIntent(result)
.addOnSuccessListener(googleAccount -> {
Log.d(TAG, "Signed in as " + googleAccount.getEmail());
// Use the authenticated account to sign in to the Drive service.
SharedPreferences.Editor edit = settings.edit();
edit.putString("GoogleDriveID", "" + googleAccount.getEmail());
edit.commit();
googleSignInAccount=googleAccount;
accountName=googleAccount.getEmail();
GoogleAccountCredential credential =
GoogleAccountCredential.usingOAuth2(
this, Collections.singleton(DriveScopes.DRIVE_FILE));
credential.setSelectedAccount(googleAccount.getAccount());
Drive googleDriveService = new Drive.Builder( AndroidHttp.newCompatibleTransport(),
new GsonFactory(), setHttpTimeout(credential)).setApplicationName("nnnnn")
.build();
service=googleDriveService;
2.second I was Getting "User Limit Exceed "
ERR-00006-Google Drive upload|StackTrace: GLOBAL::saveFileToDrive::IOException
com.google.api.client.googleapis.json.GoogleJsonResponseException:
403 Forbidden { "code": 403, "errors": [ { "domain": "usageLimits", "message": "User Rate
Limit Exceeded.
Rate of requests for user exceed configured project quota.
You may consider re-evaluating expected per-user traffic to the API and adjust project
quota limits accordingly.
You may monitor aggregate quota usage and adjust limits in the
API Console: https://console.developers.google.com/apis/api/drive.googleapis.com/quotas?
project=344828444511",
"reason": "userRateLimitExceeded", "extendedHelp":
"https://console.developers.google.com/apis/api/drive.googleapis.com/quotas?
project=************" } ],
"message": "User Rate Limit Exceeded. Rate of requests for user exceed configured project
quota.
You may consider re-evaluating expected per-user traffic to the API and adjust project
quota limits accordingly.
You may monitor aggregate quota usage and adjust limits in the API Console:
https://console.developers.google.com/apis/api/drive.googleapis.com/quotas?
project=************" }
Increased quotes Limit in Google Developer Console . but still this Error.

Strange correlation between Azure Iot hub message count and payload size

I'm sending messages from a device to my Iot Hub, of 1.8KB and 1.6KB according to the Azure Dashboard. Using the free tier (with the limit of 0.5KB per message), this should be around 4 messages total. But it's counting as 10 in the application. dashboard-image
In the dashboard image, the total data usage comes to 127.2 KB, which should be around 255 messages (127.2 KB / 0.5 KB). But according to the system, that is around 715 messages. I also measured the message size in the device, transforming it to a buffer and reading the length property (which comes around to 165 bytes) I'm using the node azure-iot sdk.
This is the code on the device that sends the data:
let message = new Message(data);
message.properties.add('source', 'node001');
client.sendEvent(message, (err) => {
if (err) {
console.log('send error: ' + err.toString());
} else {
console.log('message sent!');
}
})
and here is the payload:
[{
"RSSI": "255",
"timestamp": "2019-08-08T15:05:54.468758+00:00",
"battery": 0.02,
"temperature": 18.33,
"value_2": "-",
"value_1": 4053,
"MAC": "00158D000287044D"
}]
Using this payload and sending the message every five seconds, I expected the hub to be receiving 1152 message per day (even less, considering the payload is around 0.165KB), but it received more than 8000.
What Encoding you are using ( By any chance is it UTF32). Size of messages differs generally while using ASCII and Unicode .Could you please post full code. I just tested with C# and Azure Hub reports the same what I am transmitting and it correlates with what I see in LogAnalytics.

Google Drive REST-API Internal error 500

I'm developing an application that receives several massage queue containing 20-30 gmail addresses. My app owns a single google drive folder that must be shared with all of the users. My app uses Google drive Java client and for the HTTP calls I'm using Google batching
The problem is that I'm getting internal error 500 when I'm trying to share the folder with 30 users simultaneously by multithreading. However when I use threads synchronisation everything is fine but the performance is terrible about 0.5 second per user!
Can anyone explain Why I'm receiving this error?
500 OK
{
"code" : 500,
"errors" : [ {
"domain" : "global",
"message" : "Internal Error. User message: \"An internal error has occurred which prevented the sharing of these item(s): fileame\"",
"reason" : "internalError"
} ],
"message" : "Internal Error. User message: \"An internal error has occurred which prevented the sharing of these item(s): filename\""
}
Here is the thread code:
try {
//batch start
BatchRequest batch = service.batch();
ArrayList<String> users = readUsers(this.file);
Permission[] permissions= new Permission[users.size()];
for (int i = 0 ; i < users.size(); i++){
permissions[i]= new Permission();
permissions[i].setValue(users.get(i)+"#gmail.com");
permissions[i].setType("user");
permissions[i].setRole("writer");
service.permissions().insert(fileId, permissions[i]).setSendNotificationEmails(Boolean.FALSE) .queue(batch, callback);
}
//batch execute
batch.execute();
} catch (IOException e) {
System.out.println("An error occurred and I am " + id + ": " + e);
}

Resources