Need help implementing Adsense API in Laravel 5.4.
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hi there. I have a website with Adsense advertisement and I'd like to be able to call the Adsense api (https://developers.google.com/adsense/management/?hl=fr) and display the revenu for my ads, in my dashboard. I've installed this package https://github.com/pulkitjalan/google-apiclient but I can't figure out how it works.

I'm looking for help from someone that has experience working with the Adsense api because I don't want to pay to training for now. I've set the bounty to 1$ in case I can't find anyone to help but I'll pay you more of course as I need ongoing help with this. I'me willing to pay between 25$ and 80$ US and more over the course of the next few days / weeks for help on this matter.

Let me know if you can help.

awarded to Codeword

Crowdsource coding tasks.

2 Solutions


Hi there, :)

i never worked with laravel before, but tried to help :p

i looked up into Adsense API, i think this is what you want,

link: https://developers.google.com/adsense/management/v1.4/reference/accounts/reports/generate

this API call, will generate the revenue for you for a selected period (revenues for your account accumulated from all your ads)

hope this helps! ;)

Hi Houcern. But how do I make the call to the api from my controller ? I'm trying this: $client = new GuzzleHttp\Client(); $res = $client->get('https://www.googleapis.com/adsense/v1.4/accounts/{{ accountId }}/reports'); but I get a 401: resulted in a 401 Unauthorized response: { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", (truncated...)
randomhelprequested 3 months ago
as you can see, in the response, you are not authorized yet to get response from this API, you can see in the response message, that "message": "Login Required", so you have to login first. then use this api i gave you
Chlegou 3 months ago
Thanks Houcern. I can't figure out how to authenticate. I though I was, when using this package (https://github.com/pulkitjalan/google-apiclient) but apparently I'm not.
randomhelprequested 3 months ago
i have made a look on the API, it seems that you need to execute https://www.googleapis.com/auth/adsense.readonly first. to have it work, this will make you able to read from your data see more here, https://developers.google.com/adsense/management/v1.4/reference/accounts/reports/generate#auth and watch this video, it might help: https://www.youtube.com/watch?v=amKqe0_kiQA
Chlegou 3 months ago
Winning solution

No, I don't think this package( https://github.com/pulkitjalan/google-apiclient ) does any extra task, it just use the google-.api-client-library. I think you can directly use the google-api-client-library.
Also one more thing I would like to point out to you is that if you use outh2 then everytime you want to access adsense data, you will have to allow the application permission manually. I know this is not so good, but what to do this is how google adsense api works.
Thank you.

Hey, randomhelprequested I have emailed you the code.Thank you
Codeword 3 months ago
View Timeline