Hi Team,

We are having a web server application which works online and also offline.
Online : where we can do any change to campaigns(eg: changing the status or
changing budget)
Offline: with some Cron Trigger we dump the statistics of account/campaign
offline every day through scheduler.
So here I started upgrading my app from ClientLogin mechanism to OAuth2.0.
Before I start upgrading I have read that after receiving the access_token
and refresh token from authorization code, we need to connect to API using
access_token only and refresh token need to be saved for future use.
So here I have saved both the tokens in our data base but I create
AdwordsSession object using the ClientId,Secret,devlopertoken,useragent and
refreshToken along with customerId, but I didn't used access_token
anywhere. But I can get all the info and reports with above process. you
can see below sample code:

*After getting authorization code:*
if(authorizationCode!=null){
        log.info("authorizationCode: "+authorizationCode);
        GoogleTokenResponse tokenResponse = null;
        NetHttpTransport netHttpTransport = new NetHttpTransport();
        GoogleTokenResponse existAuthToken = null;
        try {
            JacksonFactory jacksonFactory = new JacksonFactory();
            log.info("authorizationCode:"+authorizationCode);
              tokenResponse = new
GoogleAuthorizationCodeTokenRequest(netHttpTransport,jacksonFactory,CommonFunctions.CLIENT_ID,
CommonFunctions.CLIENT_SECRET,
authorizationCode,CommonFunctions.OAUTH_REDIRECT_URL).execute();
//              gleService = new GleServices(tokenResponse);
              hs.setAttribute("authToken", tokenResponse.getAccessToken());
              hs.setAttribute("refreshToken",
tokenResponse.getRefreshToken());
              hs.setAttribute("tokenResponse", tokenResponse);
        } catch (Exception e) {
            e.printStackTrace();
        }

*//getting session Obj:*
public AdWordsSession getAdwordsSession(GoogleTokenResponse tokenResp,
String cusId){
        File temp = null;
        Credential oAuth2Credential = null;
        AdWordsSession ses = null;
        try {
            temp = File.createTempFile("ads" , ".properties");
                BufferedWriter bw = new BufferedWriter(new
FileWriter(temp));
                bw.write(refreshToken+"="+tokenResp.getRefreshToken());
                bw.newLine();
                bw.write(clientId+"="+CLIENT_ID_VALUE);
                bw.newLine();
                bw.write(clientSecret+"="+CLIENT_SECRET_ID);
                bw.newLine();
                bw.write(userAgentKey+"="+USER_AGENT);
                bw.newLine();
                bw.write(developerTokenKey+"="+DEVELOP_TOKEN);
                if(cusId!=null && cusId.length()>1){
                bw.newLine();
                bw.write(clientCustomerIdKey+"="+cusId);
                }
                bw.close();
                oAuth2Credential = new
OfflineCredentials.Builder().forApi(OfflineCredentials.Api.ADWORDS).fromFile(temp).build().generateCredential();
                ses = new
AdWordsSession.Builder().fromFile(temp).withOAuth2Credential(oAuth2Credential).build();
                createAdWordsServicesSingleton();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ses;
    }


*So here I can get all the services like below:*
CampaignServiceInterface campaignService =
adWordsServices.get(adwordsSession, CampaignServiceInterface.class);

and I can get all the adhoc reports as well as mutate,get functions works.
I will create session object for respective account only once for first
time and use the same session object through out my any modifications to
that account.

My doubt is whether am in the right flow what I doing or any wrong way
because API release notes says that to use accessToken to connect to API
always until it expires. But I can access and work cleanly with above
limited process.

So kindly let me know if this process is wrong or else any update info.

Thanks in advance.

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

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

--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to