शुरू करना

Campaign Manager 360 API की मदद से, अपने Campaign Manager 360 खाते की जानकारी को प्रोग्राम के हिसाब से ऐक्सेस किया जा सकता है. इसका इस्तेमाल कैंपेन और रिपोर्ट मैनेज करने और बनाने के लिए किया जाता है. ठीक उसी तरह जैसे Campaign Manager 360 और Report Builder की वेब सेवाओं का इस्तेमाल किया जाता है.

इस गाइड में, Campaign Manager 360 API का इस्तेमाल शुरू करने का तरीका बताया गया है.

ज़रूरी शर्तें

Campaign Manager 360 API का इस्तेमाल करने से पहले, आपको कुछ ज़रूरी शर्तें पूरी करनी होंगी:

  1. आपके पास Campaign Manager 360 खाता होना चाहिए. साइन अप करने के बारे में जानकारी के लिए, विज्ञापन देने वाले लोग या कंपनियां/एजेंसियां देखें.

  2. आपके Campaign Manager 360 खाते के लिए, एपीआई ऐक्सेस चालू होना चाहिए. ज़्यादातर खातों में यह सुविधा डिफ़ॉल्ट रूप से चालू होती है. अगर आपको पक्के तौर पर नहीं पता है, तो सहायता पाने के लिए अपने खाता प्रतिनिधि या Campaign Manager 360 की सहायता टीम से संपर्क करें.

  3. आपके पास ऐसी उपयोगकर्ता प्रोफ़ाइल होनी चाहिए जिसके पास इस खाते का ऐक्सेस हो. अपने Campaign Manager 360 खाते के एडमिन से, इस खाते से जुड़ी उपयोगकर्ता प्रोफ़ाइल बनाने के लिए कहें.

  4. Campaign Manager 360 के यूज़र इंटरफ़ेस (यूआई) में, उपयोगकर्ता प्रोफ़ाइल की अनुमतियां देखें. इन कंट्रोल से यह तय होता है कि उपयोगकर्ता प्रोफ़ाइल, एपीआई से क्या-क्या ऐक्सेस कर सकती है. इसके लिए, अलग से कोई एपीआई अनुमति नहीं दी जाती है.

प्रोजेक्ट बनाना

Campaign Manager 360 API का इस्तेमाल शुरू करने से पहले, आपको Google API Console में एक प्रोजेक्ट बनाना होगा या कोई प्रोजेक्ट चुनना होगा. इसके बाद, एपीआई की सुविधा चालू करनी होगी. इस लिंक का इस्तेमाल करने पर, आपको पूरी प्रोसेस के बारे में जानकारी मिलेगी. साथ ही, Campaign Manager 360 API अपने-आप चालू हो जाएगा.

क्रेडेंशियल जनरेट करना

Campaign Manager 360 API को किए गए सभी अनुरोधों को स्वीकार किया जाना चाहिए. अनुमति देने के बारे में खास जानकारी पाने के लिए, Google को अपने ऐप्लिकेशन की पहचान बताने और उसे अनुमति देने का तरीका पढ़ें.

इंस्टॉल किए गए ऐप्लिकेशन के फ़्लो के साथ इस्तेमाल करने के लिए, OAuth 2.0 क्लाइंट आईडी बनाने का तरीका यहां दिया गया है. सेवा खाते के फ़्लो के साथ इस्तेमाल करने के लिए क्रेडेंशियल जनरेट करने के निर्देशों के लिए, सेवा खाते गाइड देखें.

  1. Google API Console प्रोजेक्ट को कॉन्फ़िगर करने के लिए, यह तरीका अपनाएं.

  2. API Console में क्रेडेंशियल पेज खोलें.
  3. क्रेडेंशियल बनाएं > OAuth क्लाइंट आईडी पर क्लिक करें.

    1. अगर आपने इस प्रोजेक्ट के लिए, OAuth की सहमति स्क्रीन को पहले कॉन्फ़िगर नहीं किया था, तो अब आपको ऐसा करने के लिए कहा जाएगा. सहमति लेने के लिए स्क्रीन कॉन्फ़िगर करें पर क्लिक करें.

    2. उपयोगकर्ता का टाइप चुनें और बनाएं पर क्लिक करें.

    3. शुरुआती फ़ॉर्म भरें. ज़रूरत पड़ने पर, इसमें बाद में बदलाव किया जा सकता है. बदलाव करने के बाद, सेव करें पर क्लिक करें.

    4. जारी रखने के लिए, क्रेडेंशियल > क्रेडेंशियल बनाएं > OAuth क्लाइंट आईडी पर वापस जाएं.

  4. ऐप्लिकेशन टाइप के तौर पर डेस्कटॉप ऐप्लिकेशन चुनें. इसके बाद, इसे कोई नाम दें और बनाएं पर क्लिक करें.

इसके बाद, आपको OAuth 2.0 क्लाइंट आईडी और क्लाइंट सीक्रेट दिखेगा. इसे JSON फ़ॉर्मैट में डाउनलोड किया जा सकता है. साथ ही, इसे बाद में इस्तेमाल करने के लिए सेव किया जा सकता है.

क्लाइंट लाइब्रेरी इंस्टॉल करना

Campaign Manager 360 API को एचटीटीपी और JSON पर बनाया गया है. इसलिए, कोई भी स्टैंडर्ड एचटीटीपी क्लाइंट इसके लिए अनुरोध भेज सकता है और जवाबों को पार्स कर सकता है.

हालांकि, Google API क्लाइंट लाइब्रेरी की मदद से, ऐसे कॉल के लिए भाषा का बेहतर इंटिग्रेशन, बेहतर सुरक्षा, और सहायता मिलती है जिनमें उपयोगकर्ता की अनुमति ज़रूरी होती है. क्लाइंट लाइब्रेरी कई प्रोग्रामिंग भाषाओं में उपलब्ध हैं. इनका इस्तेमाल करके, एचटीटीपी अनुरोधों को मैन्युअल तरीके से सेट अप करने और जवाबों को पार्स करने से बचा जा सकता है.

शुरू करने के लिए, उस प्रोग्रामिंग भाषा को चुनें जिसका इस्तेमाल आपको साइट डेवलप करने के लिए करना है.

C#

.NET के लिए Campaign Manager 360 API की क्लाइंट लाइब्रेरी का नया वर्शन इंस्टॉल करें. हमारा सुझाव है कि आप NuGet का इस्तेमाल करके, इंस्टॉलेशन मैनेज करें.

NuGet Package Manager Console खोलें और यह निर्देश चलाएं:

Install-Package Google.Apis.Dfareporting.v3_4

ज़्यादा जानें

Java

Java के लिए, Campaign Manager 360 API की क्लाइंट लाइब्रेरी का नया वर्शन इंस्टॉल करें. हमारा सुझाव है कि आप इंस्टॉल करने के तरीके को मैनेज करने के लिए, Maven का इस्तेमाल करें.

अपनी pom.xml फ़ाइल में यह डिपेंडेंसी जोड़ें:

<dependency>
  <groupId>com.google.apis</groupId>
  <artifactId>google-api-services-dfareporting</artifactId>
  <version>v4-rev20250722-2.0.0</version>
  <exclusions>
    <exclusion>
      <groupId>com.google.guava</groupId>
      <artifactId>guava-jdk5</artifactId>
    </exclusion>
  </exclusions>
</dependency>

ज़्यादा जानें

PHP

PHP के लिए Campaign Manager 360 API की क्लाइंट लाइब्रेरी का नया वर्शन इंस्टॉल करें. हमारा सुझाव है कि इंस्टॉलेशन को मैनेज करने के लिए, Composer का इस्तेमाल करें.

टर्मिनल खोलें और यह कमांड चलाएं:

composer require google/apiclient

अगर आपने पहले से ही लाइब्रेरी इंस्टॉल की है और आपको सिर्फ़ नए वर्शन पर अपडेट करना है, तो यह तरीका अपनाएं:

composer update google/apiclient

अपने सिस्टम के हिसाब से, आपको इन कमांड को sudo के साथ जोड़ना होगा.

ज़्यादा जानें

Python

Python के लिए Campaign Manager 360 API क्लाइंट लाइब्रेरी का नया वर्शन इंस्टॉल करें. हमारा सुझाव है कि इंस्टॉल करने की प्रोसेस को मैनेज करने के लिए, pip का इस्तेमाल करें.

टर्मिनल खोलें और यह कमांड चलाएं:

pip install --upgrade google-api-python-client

अपने सिस्टम के हिसाब से, आपको इन कमांड को sudo के साथ जोड़ना होगा.

ज़्यादा जानें

Ruby

Ruby के लिए Campaign Manager 360 API की क्लाइंट लाइब्रेरी का नया वर्शन इंस्टॉल करें. हमारा सुझाव है कि आप इंस्टॉल करने के तरीके को मैनेज करने के लिए, RubyGems का इस्तेमाल करें.

टर्मिनल खोलें और यह कमांड चलाएं:

gem install google-api-client

अगर आपने पहले से ही लाइब्रेरी इंस्टॉल की है और आपको सिर्फ़ नए वर्शन पर अपडेट करना है, तो यह तरीका अपनाएं:

gem update -y google-api-client

अपने सिस्टम के हिसाब से, आपको इन कमांड को sudo के साथ जोड़ना होगा.

ज़्यादा जानें

क्लाइंट लाइब्रेरी पेज पर, Merchant Center API के साथ काम करने वाली अन्य भाषाओं के बारे में जानकारी दी गई है.

अनुरोध करें

OAuth 2.0 क्रेडेंशियल बनाने और क्लाइंट लाइब्रेरी इंस्टॉल करने के बाद, Campaign Manager 360 API का इस्तेमाल किया जा सकता है. नीचे दिए गए क्विकस्टार्ट को फ़ॉलो करके, अनुमति देने, क्लाइंट को कॉन्फ़िगर करने, और पहला अनुरोध करने का तरीका जानें.

C#

  1. क्लाइंट सीक्रेट फ़ाइल लोड करें और अनुमति देने वाले क्रेडेंशियल जनरेट करें.

    पहली बार यह चरण पूरा करने पर, आपको अपने ब्राउज़र में अनुमति देने के लिए कहा जाएगा. न्योता स्वीकार करने से पहले, पक्का करें कि आपने उस Google खाते से लॉग इन किया हो जिसके पास Campaign Manager 360 का ऐक्सेस है. आपका ऐप्लिकेशन, उस खाते की ओर से डेटा ऐक्सेस कर पाएगा जिससे फ़िलहाल लॉग इन किया गया है.

    // Load client secrets from the specified JSON file.
    GoogleClientSecrets clientSecrets;
    using(Stream json = new FileStream(pathToJsonFile, FileMode.Open, FileAccess.Read)) {
      clientSecrets = GoogleClientSecrets.Load(json);
    }
    
    // Create an asynchronous authorization task.
    //
    // Note: providing a data store allows auth credentials to be cached, so they survive multiple
    // runs of the application. This avoids prompting the user for authorization every time the
    // access token expires, by remembering the refresh token. The "user" value is used to
    // identify a specific set of credentials within the data store. You may provide different
    // values here to persist credentials for multiple users to the same data store.
    Task<UserCredential> authorizationTask = GoogleWebAuthorizationBroker.AuthorizeAsync(
        clientSecrets.Secrets,
        OAuthScopes,
        "user",
        CancellationToken.None,
        dataStore);
    
    // Authorize and persist credentials to the data store.
    UserCredential credential = authorizationTask.Result;
  2. Dfareporting के लिए, अनुमति पा चुके क्लाइंट का खाता बनाएं.

    // Create a Dfareporting service object.
    //
    // Note: application name should be replaced with a value that identifies your application.
    service = new DfareportingService(
        new BaseClientService.Initializer {
          HttpClientInitializer = credential,
          ApplicationName = "C# installed app sample"
        }
    );
  3. कोई कार्रवाई करें.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = service.UserProfiles.List().Execute();
    
    foreach (UserProfile profile in profiles.Items) {
      Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
          profile.ProfileId, profile.UserName);
    }

Java

  1. क्लाइंट सीक्रेट फ़ाइल लोड करें और अनुमति देने वाले क्रेडेंशियल जनरेट करें.

    पहली बार यह चरण पूरा करने पर, आपको अपने ब्राउज़र में अनुमति देने के लिए कहा जाएगा. न्योता स्वीकार करने से पहले, पक्का करें कि आपने उस Google खाते से लॉग इन किया हो जिसके पास Campaign Manager 360 का ऐक्सेस है. आपका ऐप्लिकेशन, उस खाते की ओर से डेटा ऐक्सेस कर पाएगा जिससे फ़िलहाल लॉग इन किया गया है.

    // Load the client secrets JSON file.
    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(
            jsonFactory, Files.newBufferedReader(Paths.get(pathToClientSecretsFile), UTF_8));
    
    // Set up the authorization code flow.
    //
    // Note: providing a DataStoreFactory allows auth credentials to be cached, so they survive
    // multiple runs of the program. This avoids prompting the user for authorization every time the
    // access token expires, by remembering the refresh token.
    GoogleAuthorizationCodeFlow flow =
        new GoogleAuthorizationCodeFlow.Builder(
                httpTransport, jsonFactory, clientSecrets, OAUTH_SCOPES)
            .setDataStoreFactory(dataStoreFactory)
            .build();
    
    // Authorize and persist credentials to the data store.
    //
    // Note: the "user" value below is used to identify a specific set of credentials in the data
    // store. You may provide different values here to persist credentials for multiple users to
    // the same data store.
    Credential credential =
        new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
  2. Dfareporting के लिए, अनुमति पा चुके क्लाइंट का खाता बनाएं.

    // Create a Dfareporting client instance.
    //
    // Note: application name below should be replaced with a value that identifies your
    // application. Suggested format is "MyCompany-ProductName/Version.MinorVersion".
    Dfareporting reporting =
        new Dfareporting.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
            .setApplicationName("dfareporting-java-installed-app-sample")
            .build();
  3. कोई कार्रवाई करें.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = reporting.userProfiles().list().execute();
    for (int i = 0; i < profiles.getItems().size(); i++) {
      System.out.printf("%d) %s%n", i + 1, profiles.getItems().get(i).getUserName());
    }

PHP

  1. क्लाइंट सीक्रेट फ़ाइल लोड करें और अनुमति देने वाले क्रेडेंशियल जनरेट करें.

    पहली बार यह चरण पूरा करने पर, आपको अपने ब्राउज़र में अनुमति देने के लिए कहा जाएगा. न्योता स्वीकार करने से पहले, पक्का करें कि आपने उस Google खाते से लॉग इन किया हो जिसके पास Campaign Manager 360 का ऐक्सेस है. आपका ऐप्लिकेशन, उस खाते की ओर से डेटा ऐक्सेस कर पाएगा जिससे फ़िलहाल लॉग इन किया गया है.

    // Create a Google_Client instance.
    //
    // Note: application name should be replaced with a value that identifies
    // your application. Suggested format is "MyCompany-ProductName".
    $client = new Google_Client();
    $client->setAccessType('offline');
    $client->setApplicationName('PHP installed app sample');
    $client->setRedirectUri(self::OAUTH_REDIRECT_URI);
    $client->setScopes(self::$OAUTH_SCOPES);
    
    // Load the client secrets file.
    $client->setAuthConfig($pathToJsonFile);
    
    // Try to load cached credentials from the token store. Using a token store
    // allows auth credentials to be cached, so they survive multiple runs of
    // the application. This avoids prompting the user for authorization every
    // time the access token expires, by remembering the refresh token.
    if (file_exists($tokenStore) && filesize($tokenStore) > 0) {
        $client->setAccessToken(file_get_contents($tokenStore));
    } else {
        // If no cached credentials were found, authorize and persist
        // credentials to the token store.
        print 'Open this URL in your browser and authorize the application.';
        printf("\n\n%s\n\n", $client->createAuthUrl());
        print 'Enter the authorization code: ';
        $code = trim(fgets(STDIN));
        $client->authenticate($code);
    
        file_put_contents($tokenStore, json_encode($client->getAccessToken()));
    }
  2. Dfareporting के लिए, अनुमति पा चुके क्लाइंट का खाता बनाएं.

    // Create a Dfareporting service object.
    $service = new Google_Service_Dfareporting($client);
  3. कोई कार्रवाई करें.

    // Retrieve and print all user profiles for the current authorized user.
    $result = $service->userProfiles->listUserProfiles();
    foreach ($result['items'] as $userProfile) {
        printf(
            "User profile \"%s\" (ID: %d) found for account %d.\n",
            $userProfile->getUserName(),
            $userProfile->getProfileId(),
            $userProfile->getAccountId()
        );
    }

Python

  1. क्लाइंट सीक्रेट फ़ाइल लोड करें और अनुमति देने वाले क्रेडेंशियल जनरेट करें.

    पहली बार यह चरण पूरा करने पर, आपको अपने ब्राउज़र में अनुमति देने के लिए कहा जाएगा. न्योता स्वीकार करने से पहले, पक्का करें कि आपने उस Google खाते से लॉग इन किया हो जिसके पास Campaign Manager 360 का ऐक्सेस है. आपका ऐप्लिकेशन, उस खाते की ओर से डेटा ऐक्सेस कर पाएगा जिससे फ़िलहाल लॉग इन किया गया है.

    # Set up a Flow object to be used if we need to authenticate.
    flow = client.flow_from_clientsecrets(
        path_to_client_secrets_file, scope=OAUTH_SCOPES)
    
    # Check whether credentials exist in the credential store. Using a credential
    # store allows auth credentials to be cached, so they survive multiple runs
    # of the application. This avoids prompting the user for authorization every
    # time the access token expires, by remembering the refresh token.
    storage = Storage(CREDENTIAL_STORE_FILE)
    credentials = storage.get()
    
    # If no credentials were found, go through the authorization process and
    # persist credentials to the credential store.
    if credentials is None or credentials.invalid:
      credentials = tools.run_flow(flow, storage,
                                   tools.argparser.parse_known_args()[0])
    
    # Use the credentials to authorize an httplib2.Http instance.
    http = credentials.authorize(httplib2.Http())
  2. Dfareporting के लिए, अनुमति पा चुके क्लाइंट का खाता बनाएं.

    # Construct a service object via the discovery service.
    service = discovery.build('dfareporting', 'v4', http=http)
  3. कोई कार्रवाई करें.

    # Construct the request.
    request = service.userProfiles().list()
    
    # Execute request and print response.
    response = request.execute()
    
    for profile in response['items']:
      print('Found user profile with ID %s and user name "%s".' %
            (profile['profileId'], profile['userName']))

Ruby

  1. क्लाइंट सीक्रेट फ़ाइल लोड करें और अनुमति देने वाले क्रेडेंशियल जनरेट करें.

    पहली बार यह चरण पूरा करने पर, आपको अपने ब्राउज़र में अनुमति देने के लिए कहा जाएगा. न्योता स्वीकार करने से पहले, पक्का करें कि आपने उस Google खाते से लॉग इन किया हो जिसके पास Campaign Manager 360 का ऐक्सेस है. आपका ऐप्लिकेशन, उस खाते की ओर से डेटा ऐक्सेस कर पाएगा जिससे फ़िलहाल लॉग इन किया गया है.

    # Load client ID from the specified file.
    client_id = Google::Auth::ClientId.from_file(path_to_json_file)
    
    # Set up the user authorizer.
    #
    # Note: providing a token store allows auth credentials to be cached, so they
    # survive multiple runs of the application. This avoids prompting the user for
    # authorization every time the access token expires, by remembering the
    # refresh token.
    authorizer = Google::Auth::UserAuthorizer.new(
      client_id, [API_NAMESPACE::AUTH_DFAREPORTING], token_store
    )
    
    # Authorize and persist credentials to the data store.
    #
    # Note: the 'user' value below is used to identify a specific set of
    # credentials in the token store. You may provide different values here to
    # persist credentials for multiple users to the same token store.
    authorization = authorizer.get_credentials('user')
    if authorization.nil?
      puts format(
        "Open this URL in your browser and authorize the application.\n\n%s" \
        "\n\nEnter the authorization code:",
        authorizer.get_authorization_url(base_url: OAUTH_REDIRECT_URI)
      )
      code = STDIN.gets.chomp
      authorization = authorizer.get_and_store_credentials_from_code(
        base_url: OAUTH_REDIRECT_URI, code: code, user_id: 'user'
      )
    end
  2. Dfareporting के लिए, अनुमति पा चुके क्लाइंट का खाता बनाएं.

    # Create a Dfareporting service object.
    #
    # Note: application name should be replaced with a value that identifies
    # your application. Suggested format is "MyCompany-ProductName".
    service = API_NAMESPACE::DfareportingService.new
    service.authorization = authorization
    service.client_options.application_name = 'Ruby installed app sample'
    service.client_options.application_version = '1.0.0'
  3. कोई कार्रवाई करें.

    // Retrieve and print all user profiles for the current authorized user.
    UserProfileList profiles = service.UserProfiles.List().Execute();
    
    foreach (UserProfile profile in profiles.Items) {
      Console.WriteLine("Found user profile with ID {0} and name \"{1}\".",
          profile.ProfileId, profile.UserName);
    }

ज़्यादा जानें

एपीआई की सभी सेवाओं के बारे में जानने के लिए, एपीआई के बारे में जानकारी पर जाएं. हर तरीके के बारे में जानकारी देने वाले पेज में, एपीआई एक्सप्लोरर एम्बेड किया गया होता है. इसका इस्तेमाल करके, सीधे अपने ब्राउज़र से टेस्ट के अनुरोध किए जा सकते हैं.

हमारी अन्य गाइड देखें. इनमें ऐडवांस विषयों के बारे में बताया गया है. साथ ही, सामान्य टास्क के लिए शुरू से आखिर तक के उदाहरण दिए गए हैं.

जब आप कोड लिखना शुरू करने के लिए तैयार हों, तो बेझिझक कोड के सैंपल का हमारा बड़ा कलेक्शन एक्सप्लोर करें. इनमें बदलाव किया जा सकता है और इन्हें अपनी ज़रूरतों के हिसाब से बढ़ाया जा सकता है.