Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JAVA Sample not working - GAM 360 dependencies for java not available - #107

Open
UsmanMaiIo opened this issue Jul 16, 2024 · 0 comments
Open

Comments

@UsmanMaiIo
Copy link

Hi Team,

Account Name : [email protected]

I am able to setup the client for GAM 360. (JAVA API)

However, I am unable to load dependencies for JAVA API related to GAM360 Campaigns.

As suggested by your online document dependency added is :

com.google.api.client

google-api-client-auth-oauth2
1.2.3-alpha

However, Getting errors:
Cannot resolve symbol 'LocalServerReceiver'

Cannot resolve symbol 'AuthorizationCodeInstalledApp'

Imports not loaded: import com.google.api.services.dfareporting.model.CampaignsListRequest;

import com.google.api.services.dfareporting.model.Pagination;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;

Request you to share the GAM360 complete document to access through JAVA API. Complete Code :
// Import libraries
import com.google.api.client.auth.oauth2.Credential;

import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;

import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;

import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;

import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;

import com.google.api.client.http.javanet.NetHttpTransport;

import com.google.api.client.json.jackson2.JacksonFactory;

import com.google.api.client.util.store.DataStoreFactory;

import com.google.api.client.util.store.FileDataStoreFactory;

import com.google.api.services.dfareporting.Dfareporting;

import com.google.api.services.dfareporting.DfareportingScopes;

import com.google.api.services.dfareporting.model.Campaign;

import com.google.api.services.dfareporting.model.CampaignsListRequest;

import com.google.api.services.dfareporting.model.Pagination;

import java.io.File;

import java.util.ArrayList;

import java.util.List;

public class GetCampaigns {

// Replace with your values (instructions in comments)
private static final String CLIENT_ID = ""
private static final String CLIENT_SECRET = ""
private static final String REDIRECT_URI = ""
private static final String APPLICATION_NAME = ""
private static final String NETWORK_ID = ""

public static void main(String[] args) throws Exception {

   // Authorization (refer to Google Ads documentation for detailed setup)

   final Credential credential = authorize(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);



   // Create Dfareporting service object
   final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();

   final JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();

   final Dfareporting dfareporting = new Dfareporting.Builder(httpTransport, jsonFactory, credential)
           .setApplicationName(APPLICATION_NAME)
           .build();



   // List campaigns
   List<Campaign> campaigns = listCampaigns(dfareporting, NETWORK_ID);



   System.out.println("Retrieved Campaigns:");

   for (Campaign campaign : campaigns) {

       System.out.println("  - ID: " + campaign.getId() + ", Name: " + campaign.getName());

   }

}

public static Credential authorize(final String CLIENT_ID, final String CLIENT_SECRET, final String REDIRECT_URI) throws Exception {
// Replace with your actual paths
final File DATA_STORE_DIR = new File(System.getProperty("user.home"), ".credentials/dfareporting");

   final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();

   final JacksonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();

   final DataStoreFactory DATA_STORE_FACTORY = new FileDataStoreFactory(DATA_STORE_DIR);



   // Build flow and trigger user authorization request.

   GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(

           HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, DfareportingScopes.all())

           .setDataStoreFactory(DATA_STORE_FACTORY)

           .setAccessType("offline")

           .build();



   **LocalServerReceiver** receiver = new **LocalServerReceiver**.Builder().setPort(8888).build();
   return new **AuthorizationCodeInstalledApp**(flow, receiver).authorize("user");

}

public static List listCampaigns(final Dfareporting dfareporting, final String network)

Regards,
Usman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant