So, we have an existing job setup to get Double Click reports. To authenticate the credential we make a call to the API like below (in .Net C#)using com.doubleclick.dfa;
OrganizationFactory.getOrganization(uid, pwd, Url);
Now we are planning to use the new .Net API for DFA and OAuth2. In the Sample Applications available on Google, Tasks.SimpleOAuth2, it spawns a browser window to get the Authorization Code.
My question is how can I get the Authorization code without spawning a browser window, as this is going to be a background job? And the users accounts are created by us and we have the credentials.
Any suggestions? Thanks.
Thanks for your response. I read a bit more on the DFA Reporting API and now am a bit more clear about my issue.
The authentication I am looking for is "Service Accounts" as described here: https://developers.google.com/accounts/docs/OAuth2
I was able to write a code snippet that would get me the access token for my "google account" .
What I am trying to do:
Under our account we have got various "DFA accounts". I am trying to connect to my account using the access token that I generate at run-time. The JSON I receive through my method looks like below:
{
"access_token" : "ya29.......FJ1A",
"token_type" : "Bearer",
"expires_in" : 3600
}
Where I am:
I have got VS 2012 sample downloaded that has examples on how to make calls to DFA service (using the user prompt that I am trying to avoid here). I have adopted the code and intialized the DfaUser object as shown here: https://code.google.com/p/google-api-dfa-dotnet/wiki/HowToUseADfaUser (DfaUser(Dictionary<string, string> headers) constructor). I use the access token I got for the "authToken" header value.
Alternate tried so far:
I also tried the approach described here Configure your DfaUser to use OAuth: https://code.google.com/p/google-api-dfa-dotnet/wiki/UsingOAuth
I do not have a refresh token value so I did not set anything there.
Error:
When executing code with above setup, I get error at
UserRecordSet users = service.getUsersByCriteria(searchCriteria); //service is UserRemoteService
Error message: org.apache.ws.security.WSSecurityException: General security error (WSSecurityEngine: Callback supplied no password for: <username>)
Error for Alternate:
The error I get for trying the alternate method is: 101026 - Invalid OAuth2 token sent with this request.
Would you be able to point out what I am doing wrong and what should I modify? Your response is greatly appreciated.
Thanks.
Hi Joseph DiLallo,We are developing a windows service to retrieve the DFA data using "Google.Apis.Dfareporting.v1.1.cs" API in C#.We can't open the browser through windows service even once. Is there a solution for our problem. We want our systemfully automated that we want to avoid opening the browser to generate credential even once."Installed Application Flow" for OAuth2 is cumbersome to follow, Can you share the simple steps or the sample c# codeto auto-authenticate.
Hi Joseph,I don't find dfa api listed in Google OAuth 2.0 Playground. Can you please clarify which option to choose.
| private static readonly string DfaReportingScope = DfareportingService.Scopes.Dfareporting.GetStringValue(); |
| private const string DevStorageScopeReadOnly = "https://www.googleapis.com/auth/devstorage.read_only"; private const string[] scopes = new string[] { DfaReportingScope, DevStorageScopeReadOnly }; |
Hi Joseph,I have set the refreshtoken on authorization state in the below given code step -AuthorizationMgr.SetCachedRefreshToken(storage, key, new AuthorizationState(new string[] { })
{
AccessToken = "*******",
RefreshToken = "******"
});Can you please share any sample code.
IAuthorizationState state = new AuthorizationState(new[] { "https://www.googleapis.com/auth/dfareporting", "https://www.googleapis.com/auth/devstorage.read_only" });
string refreshToken = "REFRESH_TOKEN_HERE";state.RefreshToken = refreshToken;return state;
Hi Joseph,
Tried your below suggestion, I got the error - "Error occurred while sending a direct message or getting the response". I was caught in the catch block -
catch (DotNetOpenAuth.Messaging.ProtocolException ex) :)
If you could share me a plug-in-play working "private static IAuthorizationState GetAuthorization(NativeApplicationClient client)" method sample, for authenticating without the user intervention (without the browser open for "allow access" button click).
Regards,
Joseph
Error: redirect_uri_mismatch