Friday, March 2, 2012

Digest for adsense-api@googlegroups.com - 14 Messages in 4 Topics

Group: http://groups.google.com/group/adsense-api/topics

    Sebastian Vaggi <svaggi@gmail.com> Mar 01 01:15PM -0800  

    Hi, I am using PHP to get the token, i get a Token that only let me get the
    reports for 3600 seconds, how can i make the token to Persist forever ? i
    cant find the correct info in how to use the refresh token to get a new
    token.
     
    Regards
    Sebastian

     

    Silvano Luciani <silvano.luciani@google.com> Mar 01 02:12PM -0800  

    Hello Sebastian,
     
    If you are developing your own implementation to handle the OAuth 2.0
    authentication flow, this is the documentation that you need to
    follow:
    https://developers.google.com/accounts/docs/OAuth2WebServer
     
    You need to request offline access for your application, so that with
    the access token you will receive also a refresh token that you can
    exchange for a new access token when needed. The refresh token never
    expires, but its validity can be manually revoked by the user:
    https://developers.google.com/accounts/docs/OAuth2WebServer#offline
     
    If you use the Google API Php Client Library the offline access is
    requested by default, so all you need to do is save the access token
    and the refresh token, use the access token until it expires, obtain a
    new access token using the refresh token.
    http://code.google.com/p/google-api-php-client/
     
    Cheers,
    Silvano
     
    --
    Silvano Luciani | Developer Programs Engineer
     
    Google UK Limited
    Registered Office: Belgrave House, 76 Buckingham Palace Road, London
    SW1W 9TQ
    Registered in England Number: 3977902
     

     

    Max Glaser <max.glaser@gmail.com> Feb 29 01:35PM -0800  

    Hello Silvano,
     
    My problem with the URL caching has been solved with the newest Google API
    Client version for PHP.
     
    Now I want to understand correctly the metrics PAGE_VIEWS_CTR and
    TOTAL_EARNINGS from the report collection
    (http://code.google.com/apis/adsense/management/v1/reference.html#collection_reports)
     
    - PAGE_VIEWS_CTR should be the "Page CTR" from the AdSense front-end. Isn't
    it? I always get from the API a wrong value. For example 0.02, but the
    front-end shows 1.96
     
    - TOTAL_EARNINGS should be the total sum of the different products
    (content, search, etc.) I am right here? But I always get 0 from the API.
     
     
    Thank You four your help!
     
    Regards,
    Max Glaser

     

    Max Glaser <max.glaser@gmail.com> Mar 01 04:55AM -0800  

    It seems that the API is returning *PAGE_VIEWS_CTR / 100* of the value *Page
    CTR* of AdSense frotend.
     
    Regards,
    Max Glaser

     

    Silvano Luciani <silvano.luciani@google.com> Mar 01 05:47AM -0800  

    Hello Max,
     
    The AdSense website shows the PAGE CTR as a percentage, while the
    value returned from the API is the ratio. So 1.96% ~= 0.02.
     
    About the earnings, you should be using the EARNINGS metric. Let me
    know if after changing metric you still experience discrepancy between
    the earnings shown in the AdSense website and what the API returns to
    you.
     
    Cheers,
    Silvano
     
    --
    Silvano Luciani | Developer Programs Engineer
     
    Google UK Limited
    Registered Office: Belgrave House, 76 Buckingham Palace Road, London
    SW1W 9TQ
    Registered in England Number: 3977902
     

     

    Max Glaser <max.glaser@gmail.com> Mar 01 06:22AM -0800  

    Hello Silvano,
     
    Thank you for the quick reply!
     
    Yes, your right, the PAGE_VIEWS_CTR is a ratio and has the same value as
    the Page CTR on the frontend.
     
    The metric EARNINGS is also quite accurate to the value of the frontend
    with a small delay, but it only returns the value of the product *AdSense
    for Content*. I still suppose that the metric TOTAL_EARNINGS should return
    the earnings sum of all products (content, search, etc.). But currently
    this metric is always empty.
     
    Regards,
    Max

     

    Silvano Luciani <silvano.luciani@google.com> Mar 01 07:04AM -0800  

    Hello Max,
     
    the metric EARNINGS should return the value for all the products that
    you are using and that are generating earnings, that is the metric
    that you should use.
    Can you check in the AdSense website if under Performance reports >
    Products there are more products listed?
     
    Cheers,
    Silvano
     
    --
    Silvano Luciani | Developer Programs Engineer
     
    Google UK Limited
    Registered Office: Belgrave House, 76 Buckingham Palace Road, London
    SW1W 9TQ
    Registered in England Number: 3977902
     

     

    Max Glaser <max.glaser@gmail.com> Mar 01 07:31AM -0800  

    Silvano, I have several products, but the metric EARNINGS only returns the
    value of the product AdSense for Content.
     
    On Thursday, March 1, 2012 11:04:24 AM UTC-4, Silvano Luciani wrote:

     

    Silvano Luciani <silvano.luciani@google.com> Mar 01 08:45AM -0800  

    Hi Max,
     
    by any chance are you filtering by AdClient ID?
     
    Cheers,
    Silvano
     
    --
    Silvano Luciani | Developer Programs Engineer
     
    Google UK Limited
    Registered Office: Belgrave House, 76 Buckingham Palace Road, London
    SW1W 9TQ
    Registered in England Number: 3977902
     

     

    Max Glaser <max.glaser@gmail.com> Mar 01 11:16AM -0800  

    Hi Silvano,
     
    Yes, I was filtering by AdClient ID. Now, EARNINGS is showing the sum of
    all products :-) Thank You!
     
    Could you tell me the meaning of the metric TOTAL_EARNINGS?
     
    Regards,
    Max Glaser
     
     
    On Thursday, March 1, 2012 12:45:51 PM UTC-4, Silvano Luciani wrote:

     

    "Raúl Mellado" <raulmellado@gmail.com> Feb 29 11:23PM -0800  

    Hi Silvano,
     
    I have been going through all examples in google-api-php-client (v 0.4.9
    beta), and this is what I have found:
     
    1. In GetAllCustomChannels, I was getting the names for the custom
    channels, but not the ids, checking your code you
    have $customChannel['productCode'] (#47), but with a var_dump I saw that
    the property is called "code", so I changed $customChannel['productCode']
    to $customChannel['code'] and the id was shown then.
     
    2. There are 2 examples not working for me, these
    are:GetAllAdUnitsForCustomChannel and GetAllCustomChannelsForAdUnit.
     
    I have replaced:
     
    define('CUSTOM_CHANNEL_ID', 'my channel id here');
    define('AD_UNIT_ID', 'my ad unit id here');
     
    with values coming from requests using the API, to get all channel
    ids/ad unit ids
     
    Maybe I am doing something wrong here?
     
     
    The rest of examples work beautifully for me, thanks for the great code,
    it is priceless!
     
    Cheers!
     
     
    Raul

     

    Silvano Luciani <silvano.luciani@google.com> Mar 01 05:19AM -0800  

    Hello Raúl,
     
    Thanks for notifying us of 1, I will fix it ASAP!
     
    For GetAllAdUnitsForCustomChannel and GetAllCustomChannelsForAdUnit
    you need to pass the account ID and ad client ID:
    http://code.google.com/p/google-api-php-client/source/browse/trunk/examples/adsense/examples/GetAllAdUnitsForCustomChannel.php#31
     
    You can use the 'Get All Accounts' example to retrieve your account ID/
    s and 'Get All Ad Clients' to retrieve your Ad Client/s.
     
    Cheers,
    Silvano
     
    --
    Silvano Luciani | Developer Programs Engineer
     
    Google UK Limited
    Registered Office: Belgrave House, 76 Buckingham Palace Road, London
    SW1W 9TQ
    Registered in England Number: 3977902
     

     

    "Raúl Mellado" <raulmellado@gmail.com> Feb 29 10:55PM -0800  

    Hi Silvano,
     
    my apologies for having "doubted" your code for a second :-) I created
    the sqlite db and it worked like a charm! You made my day :-)
     
    One final question: I want to make my WordPress plugin noobie-friendly,
    so I want the users to do as little as possible to start using it. Could
    you please confirm this is the simplest way for a user to get my plugin up
    and running in, let's say, Blog A and Blog B?
     
    1. User goes to Google APIs site, activates Adsense API using his Google
    account.
    2. User creates a new Project (let's call it "WP Adsense API Stats")
    3. Within that project, user creates a client ID for blog A, entering
    redirect URL + javascript origins with URL for Blog A.
    4. User enters Client ID + Client secret + Developer key (q1: is this
    last one needed?) in the Wordpress Backend
    5. User authenticates Blog A, using oAuth against Google APIs (q2: is
    this authentication needed only once per url?)
    6. User does steps 3, 4 and 5 again for Blog B
    7. No more interaction from user side, my plugin can then collect stats
    without the user having to mess with APIs, authentication, etc? (again, I
    want to make as simple for the user as possible)
    8. Users thank me for a great and simple to use plugin. I thank Silvano
    for his great help. Silvano thanks whoever invented beer in the first
    place. Raul invites Silvano to some beers.
     
    q3: Would this be the way to go? No shortcuts/even simpler ways for the
    user here?
     
    q4: do I need to store user + token in Wordpress db (maybe this is
    simpler here than using a sqlite database)? My guess here is that this time
    is going to change on each session, right?
     
    Once more, thanks a lot for your great help, it's been really useful!
     
     
    Raul
     
    PS. To put you in perspective: I have found a couple of plugins that do
    something similar to what I am trying to accomplish (get adsense stats from
    WordPress backend), but they were coded before the API was public, so here
    is how they work:
     
    1. User enters Google username/password, which are then stored
    unencrypted (*sigh*) in Wordpress db
    2. WP plugin logins on Adsense using stored user/pass and scrapes page,
    showing earnings in WP backend.
     
    I am trying to do it in a more elegant (and safe) way, using the
    available Management API :-)

     
     
     
     
     
    On Wednesday, February 29, 2012 9:15:19 PM UTC+11, Silvano Luciani wrote:

     

    Silvano Luciani <silvano.luciani@google.com> Mar 01 03:29AM -0800  

    Hello Raúl,
     
    you could use the same Client ID for both blogs, adding redirect URIs
    and Javascript origins for both.
    When authenticating from Blog A you would set in the PHP client Blog A
    redirect URI, Blog B redirect URI when authenticating from Blog B.
    If you use the same Client ID, the authentication is valid on both
    blogs. If you use offline_access, the user will have to authorize the
    plugin only the first time it's being used, then the token will be
    automatically refreshed when needed.
     
    If you want to store a token, you can use anything that will allow you
    to save strings. When you request offline access, you receive a json
    object that contains access_token (the value you need to use to
    authorize requests), expires_in (the validity of the token in seconds)
    and a refresh_token(that you use to retrieve another token when it has
    expired). So basically you can save the access_token for expires_in
    seconds since you have received it, then you'll need to refresh it
    using the refresh token. The refresh token will be the same unless the
    user revokes the authorization to the application.
     
    If you want to know more about the flow, you can read our docs on
    Using OAuth 2.0 for Web Server Applications:
    https://developers.google.com/accounts/docs/OAuth2WebServer
     
    Cheers,
    Silvano
     
    --
    Silvano Luciani | Developer Programs Engineer
     
    Google UK Limited
    Registered Office: Belgrave House, 76 Buckingham Palace Road, London
    SW1W 9TQ
    Registered in England Number: 3977902
     

     

You received this message because you are subscribed to the Google Group adsense-api.
You can post via email.
To unsubscribe from this group, send an empty message.
For more options, visit this group.

--
You received this message because you are subscribed to the Google Groups "AdSense API Forum" group.
To post to this group, send email to adsense-api@googlegroups.com.
To unsubscribe from this group, send email to adsense-api+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/adsense-api?hl=en.

No comments:

Post a Comment