Google Ads Links: insert

يجب تقديم تفويض.

ينشئ رابطًا على موقع الويب-"إعلانات Google". جرِّبه الآن أو اطّلِع على مثال.

الطلب

طلب HTTP

POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/entityAdWordsLinks

المَعلمات

اسم المعلَمة القيمة الوصف
مَعلمات المسار
accountId string رقم تعريف حساب "إحصاءات Google" لإنشاء الرابط من أجله.
webPropertyId string رقم تعريف الموقع الإلكتروني لإنشاء الرابط من أجله.

التفويض

يتطلب هذا الطلب تفويضًا بالنطاق التالي (مزيد من المعلومات عن المصادقة والترخيص).

النطاق
https://www.googleapis.com/auth/analytics.edit

نص الطلب

في نص الطلب، أدخِل مرجع روابط "إعلانات Google" يحتوي على السمات التالية:

اسم الموقع القيمة الوصف Notes
الخصائص المطلوبة
adWordsAccounts[] list قائمة بحسابات العملاء في "إعلانات Google". ولا يمكن أن تكون هذه حسابات على "مركز عملائي". يجب ملء هذا الحقل عند إنشاء رابط مع حساب "إعلانات Google". لا يمكن أن يكون الحقل فارغًا. قابل للكتابة
adWordsAccounts[].customerId string الرقم التعريفي للعميل. يجب ملء هذا الحقل عند إنشاء رابط مع حساب "إعلانات Google".
name string اسم الرابط يجب ملء هذا الحقل عند إنشاء رابط مع حساب "إعلانات Google". قابل للكتابة

الإجابة

في حال نجاحها، تعرض هذه الطريقة مرجع روابط "إعلانات Google" في نص الاستجابة.

أمثلة

ملاحظة: إنّ الأمثلة المرتبطة بالرموز والمتوفرة لهذه الطريقة لا تمثّل كل لغات البرمجة المتوافقة (يُرجى مراجعة صفحة مكتبات البرامج للاطّلاع على قائمة باللغات المتوافقة).

Java

تستخدم مكتبة عملاء Java.

/*
 * Note: this code assumes you have an authorized Analytics service object.
 * See the Google Ads Links Developer Guide for details.
 */

/*
 * This request creates a new Google Ads Link.
 */

// Construct a list of AdWordsAccounts.
AdWordsAccount adWordsAccount = new AdWordsAccount();
adWordsAccount.setCustomerId("123-456-7890");
List<AdWordsAccount> adWordsAccounts = Arrays.asList(adWordsAccount);

// Construct the body of the request.
EntityAdWordsLink adWordsLink = new EntityAdWordsLink();
adWordsLink.setAdWordsAccounts(adWordsAccounts);
adWordsLink.setName("Google Ads Link");

try{
  analytics.management().webPropertyAdWordsLinks().insert("123456",
      "UA-123456-1", adWordsLink).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}

PHP

تستخدم مكتبة برامج PHP.

/**
 * Note: This code assumes you have an authorized Analytics service object.
 * See the Google Ads Links Developer Guide for details.
 */

/**
 * This request creates a new Google Ads Link.
 */

// Construct an Google Ads account object.
$adWordsAccount = new Google_Service_Analytics_AdWordsAccount();
$adWordsAccount->setCustomerId("123-456-7890");

// Construct the body of the request.
$adWordsLink = new Google_Service_Analytics_EntityAdWordsLink();
$adWordsLink->setName('Google Ads Link');
$adWordsLink->setAdWordsAccounts(array($adWordsAccount));

try {
  $analytics->management_webPropertyAdWordsLinks->insert('123456',
      'UA-123456-1', $adWordsLink);

} catch (apiServiceException $e) {
  print 'There was an Analytics API service error '
      . $e->getCode() . ':' . $e->getMessage();

} catch (apiException $e) {
  print 'There was a general API error '
      . $e->getCode() . ':' . $e->getMessage();
}

Python

تستخدم مكتبة برامج Python.

# Note: This code assumes you have an authorized Analytics service object.
# See the Google Ads Links Developer Guide for details.

# This request creates a new Google Ads Link.
try:
  analytics.management().webPropertyAdWordsLinks().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      body={
          'adWordsAccounts': [
              {
                  'customerId': '123-456-7890'
              }
          ],
          'name': 'Google Ads Link'
      }
  ).execute()

except TypeError, error:
  # Handle errors in constructing a query.
  print 'There was an error in constructing your query : %s' % error

except HttpError, error:
  # Handle API errors.
  print ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))

JavaScript

تستخدم مكتبة برامج JavaScript.

/*
 * Note: This code assumes you have an authorized Analytics client object.
 * See the Google Ads Links Developer Guide for details.
 */

/*
 * This request creates a new Google Ads Link.
 */
function insertAdWordsLink() {
  var request = gapi.client.analytics.management.webPropertyAdWordsLinks.insert(
    {
      'accountId': '123456',
      'webPropertyId': 'UA-123456-1',
      'resource': {
        'adWordsAccounts': [ { 'customerId': '123-456-7890'} ],
        'name': 'Google Ads Link'
      }
    });
  request.execute(function (response) { // Handle the response. });
}

تجربة

استخدِم مستكشف واجهات برمجة التطبيقات أدناه لطلب هذه الطريقة على البيانات المباشرة والاطّلاع على الردّ. ويمكنك بدلاً من ذلك تجربة المستكشف المستقل.