इस शुरुआती लेख में, Google Marketing Platform Admin API के लिए अनुरोध बनाए जाते हैं. साथ ही, उन जवाबों को देखा जाता है जिनमें बताए गए Google Marketing Platform संगठन से लिंक किए गए Google Analytics खातों की सूची होती है.
अपने स्थानीय एनवायरमेंट में प्रोग्रामिंग भाषा के एसडीके या REST API का इस्तेमाल करके, इस क्विकस्टार्ट को पूरा किया जा सकता है.
ज़रूरी शर्तें
क्विकस्टार्ट गाइड को पूरा करने के लिए, आपको ये काम करने होंगे:
- Google Cloud प्रोजेक्ट सेट अप करना और Google Marketing Platform Admin API चालू करना
- अपनी लोकल मशीन पर:
- Google Cloud के साथ इंस्टॉल, शुरू, और पुष्टि करना
- अपनी भाषा के लिए SDK टूल इंस्टॉल करना
Google Cloud प्रोजेक्ट सेट अप करना
अपना Google Cloud प्रोजेक्ट सेट अप करें और Google Marketing Platform Admin API को चालू करें.
नया Google Cloud प्रोजेक्ट चुनने या बनाने के लिए इस बटन पर क्लिक करें. इससे Google Marketing Platform Admin API अपने-आप चालू हो जाएगा:
Google Marketing Platform Admin API को चालू करनाGoogle Cloud सेट अप करना
अपनी लोकल मशीन पर, Google Cloud को सेट अप करें और पुष्टि करें.
-
Google Cloud को इंस्टॉल और शुरू करें.
-
अगर आपने पहले Google Cloud इंस्टॉल किया था, तो यह पक्का करें कि आपके
gcloud
कॉम्पोनेंट अपडेट हो गए हों. इसके लिए, यह कमांड चलाएं.gcloud components update
-
Google Cloud के साथ पुष्टि करने के लिए, यह कमांड चलाकर, लोकल ऐप्लिकेशन डिफ़ॉल्ट क्रेडेंशियल (ADC) फ़ाइल जनरेट करें. कमांड से शुरू किए गए वेब फ़्लो का इस्तेमाल, आपके उपयोगकर्ता क्रेडेंशियल देने के लिए किया जाता है.
gcloud auth application-default login --scopes="https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/marketingplatformadmin.analytics.read"
ध्यान दें कि Google Marketing Platform Admin API के लिए ज़रूरी स्कोप, कमांड में कैसे बताए गए हैं.
ज़्यादा जानकारी के लिए, ऐप्लिकेशन के लिए डिफ़ॉल्ट क्रेडेंशियल सेट अप करना लेख पढ़ें.
Google Marketing Platform Admin API के लिए कोटा प्रोजेक्ट की ज़रूरत होती है, जो डिफ़ॉल्ट रूप से सेट नहीं होता. कोटा प्रोजेक्ट सेट करने का तरीका जानने के लिए, उपयोगकर्ता क्रेडेंशियल गाइड देखें.
अपने Google Marketing Platform संगठन का आईडी देखना
Google Marketing Platform Admin API का इस्तेमाल करने के लिए, आपको अपने Google Marketing Platform के संगठन आईडी की पहचान करनी होगी. Google Marketing Platform में लॉगिन करें, एडमिन डायलॉग पर जाएं, अपना संगठन चुनें, और संगठन की जानकारी में जाकर, संगठन का आईडी नोट करें.
Google Marketing Platform Admin API को किए जाने वाले सभी अनुरोधों में, organizations/ORGANIZATION_ID
फ़ॉर्मैट में संगठन का आईडी शामिल होना चाहिए.
अपनी प्रोग्रामिंग भाषा के लिए SDK सेट अप करना
अपनी प्रोग्रामिंग भाषा के लिए SDK टूल इंस्टॉल करने के लिए, अपनी लोकल मशीन पर इनमें से किसी टैब पर क्लिक करें.
Java
PHP
Python
Node.js
.NET
Ruby
REST
नीचे दिए गए निर्देशों का पालन करके, अपने एनवायरमेंट वैरिएबल कॉन्फ़िगर करें.
ORGANIZATION_ID
की जगह अपने Google Marketing Platform के संगठन का आईडी डालें.PROJECT_ID
की जगह अपने Google Cloud प्रोजेक्ट का आईडी डालें.
एपीआई कॉल करना
अब Google Marketing Platform API का इस्तेमाल करके, Google Analytics खातों की सूची बनाई जा सकती है. ये खाते, Google Marketing Platform के किसी संगठन से लिंक होते हैं. एपीआई को पहली बार कॉल करने के लिए, यह कोड चलाएं:
Java
तुरंत शुरू करने की सुविधा का इस्तेमाल करते समय, .setPageSize
और .setPageToken
पर कॉल करने की सुविधा हटाएं.
import com.google.ads.marketingplatform.admin.v1alpha.AnalyticsAccountLink; import com.google.ads.marketingplatform.admin.v1alpha.ListAnalyticsAccountLinksRequest; import com.google.ads.marketingplatform.admin.v1alpha.MarketingplatformAdminServiceClient; import com.google.ads.marketingplatform.admin.v1alpha.OrganizationName; public class SyncListAnalyticsAccountLinks { public static void main(String[] args) throws Exception { syncListAnalyticsAccountLinks(); } public static void syncListAnalyticsAccountLinks() throws Exception { // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (MarketingplatformAdminServiceClient marketingplatformAdminServiceClient = MarketingplatformAdminServiceClient.create()) { ListAnalyticsAccountLinksRequest request = ListAnalyticsAccountLinksRequest.newBuilder() .setParent(OrganizationName.of("[ORGANIZATION]").toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .build(); for (AnalyticsAccountLink element : marketingplatformAdminServiceClient.listAnalyticsAccountLinks(request).iterateAll()) { // doThingsWith(element); } } } }
PHP
use Google\Ads\MarketingPlatform\Admin\V1alpha\AnalyticsAccountLink; use Google\Ads\MarketingPlatform\Admin\V1alpha\Client\MarketingplatformAdminServiceClient; use Google\Ads\MarketingPlatform\Admin\V1alpha\ListAnalyticsAccountLinksRequest; use Google\ApiCore\ApiException; use Google\ApiCore\PagedListResponse; /** * Lists the Google Analytics accounts link to the specified Google Marketing * Platform organization. * * @param string $formattedParent The parent organization, which owns this collection of Analytics * account links. Format: organizations/{org_id} * Please see {@see MarketingplatformAdminServiceClient::organizationName()} for help formatting this field. */ function list_analytics_account_links_sample(string $formattedParent): void { // Create a client. $marketingplatformAdminServiceClient = new MarketingplatformAdminServiceClient(); // Prepare the request message. $request = (new ListAnalyticsAccountLinksRequest()) ->setParent($formattedParent); // Call the API and handle any network failures. try { /** @var PagedListResponse $response */ $response = $marketingplatformAdminServiceClient->listAnalyticsAccountLinks($request); /** @var AnalyticsAccountLink $element */ foreach ($response as $element) { printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); } } catch (ApiException $ex) { printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); } } /** * Helper to execute the sample. * * This sample has been automatically generated and should be regarded as a code * template only. It will require modifications to work: * - It may require correct/in-range values for request initialization. * - It may require specifying regional endpoints when creating the service client, * please see the apiEndpoint client configuration option for more details. */ function callSample(): void { $formattedParent = MarketingplatformAdminServiceClient::organizationName('[ORGANIZATION]'); list_analytics_account_links_sample($formattedParent); }
Python
# This snippet has been automatically generated and should be regarded as a # code template only. # It will require modifications to work: # - It may require correct/in-range values for request initialization. # - It may require specifying regional endpoints when creating the service # client as shown in: # https://googleapis.dev/python/google-api-core/latest/client_options.html from google.ads import marketingplatform_admin_v1alpha def sample_list_analytics_account_links(): # Create a client client = marketingplatform_admin_v1alpha.MarketingplatformAdminServiceClient() # Initialize request argument(s) request = marketingplatform_admin_v1alpha.ListAnalyticsAccountLinksRequest( parent="parent_value", ) # Make the request page_result = client.list_analytics_account_links(request=request) # Handle the response for response in page_result: print(response)
Node.js
इस्तेमाल: node packages/google-marketingplatform-admin/samples/quickstart.js organizations/ORGANIZATION_ID.
/** * This snippet has been automatically generated and should be regarded as a code template only. * It will require modifications to work. * It may require correct/in-range values for request initialization. * TODO(developer): Uncomment these variables before running the sample. */ /** * Required. The parent organization, which owns this collection of Analytics * account links. Format: organizations/{org_id} */ // const parent = 'abc123' /** * Optional. The maximum number of Analytics account links to return in one * call. The service may return fewer than this value. * If unspecified, at most 50 Analytics account links will be returned. The * maximum value is 1000; values above 1000 will be coerced to 1000. */ // const pageSize = 1234 /** * Optional. A page token, received from a previous ListAnalyticsAccountLinks * call. Provide this to retrieve the subsequent page. * When paginating, all other parameters provided to * `ListAnalyticsAccountLinks` must match the call that provided the page * token. */ // const pageToken = 'abc123' // Imports the Admin library const {MarketingplatformAdminServiceClient} = require('@google-ads/marketing-platform-admin').v1alpha; // Instantiates a client const adminClient = new MarketingplatformAdminServiceClient({fallback: true}); async function callListAnalyticsAccountLinks() { // Construct request const request = { parent, }; // Run request const iterable = adminClient.listAnalyticsAccountLinksAsync(request); for await (const response of iterable) { console.log(response); } } callListAnalyticsAccountLinks();
.NET
using Google.Ads.MarketingPlatform.Admin.V1Alpha; using Google.Api.Gax; using System; public sealed partial class GeneratedMarketingplatformAdminServiceClientSnippets { /// <summary>Snippet for ListAnalyticsAccountLinks</summary> /// <remarks> /// This snippet has been automatically generated and should be regarded as a code template only. /// It will require modifications to work: /// - It may require correct/in-range values for request initialization. /// - It may require specifying regional endpoints when creating the service client as shown in /// https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint. /// </remarks> public void ListAnalyticsAccountLinks() { // Create client MarketingplatformAdminServiceClient marketingplatformAdminServiceClient = MarketingplatformAdminServiceClient.Create(); // Initialize request argument(s) string parent = "organizations/[ORGANIZATION]"; // Make the request PagedEnumerable<ListAnalyticsAccountLinksResponse, AnalyticsAccountLink> response = marketingplatformAdminServiceClient.ListAnalyticsAccountLinks(parent); // Iterate over all response items, lazily performing RPCs as required foreach (AnalyticsAccountLink item in response) { // Do something with each item Console.WriteLine(item); } // Or iterate over pages (of server-defined size), performing one RPC per page foreach (ListAnalyticsAccountLinksResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (AnalyticsAccountLink item in page) { // Do something with each item Console.WriteLine(item); } } // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required int pageSize = 10; Page<AnalyticsAccountLink> singlePage = response.ReadPage(pageSize); // Do something with the page of items Console.WriteLine($"A page of {pageSize} results (unless it's the final page):"); foreach (AnalyticsAccountLink item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; } }
REST
यह अनुरोध भेजने के लिए, कमांड लाइन से curl कमांड चलाएं या अपने ऐप्लिकेशन में REST कॉल शामिल करें.
curl -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \\ -H "x-goog-user-project: ${PROJECT_ID}" -H "Content-Type: application/json" \\ https://marketingplatformadmin.googleapis.com/v1alpha/organizations/${ORGANIZATION_ID}/analyticsAccountLinks
सैंपल कोड, दिए गए Google Marketing Platform संगठन से लिंक किए गए Google Analytics खातों की सूची के साथ एक रिस्पॉन्स प्रिंट करता है:
{
"analyticsAccountLinks": [
{
"name": "organizations/0a123456789-wxyz/analyticsAccountLinks/1234567890",
"analyticsAccount": "analyticsadmin.googleapis.com/accounts/1234567890",
"displayName": "Demo Account",
"linkVerificationState": "LINK_VERIFICATION_STATE_VERIFIED"
}
]
}
बधाई हो! आपने Google Marketing Platform API को अपना पहला अनुरोध भेजा है.