Profile User Links: insert

अनुमति की ज़रूरत है

दिए गए व्यू (प्रोफ़ाइल) में एक नया उपयोगकर्ता जोड़ता है. इसे अभी आज़माएं या उदाहरण देखें.

स्टैंडर्ड पैरामीटर के अलावा, यह तरीका पैरामीटर टेबल में दिए गए पैरामीटर के साथ काम करता है.

अनुरोध

एचटीटीपी अनुरोध

POST https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/profiles/profileId/entityUserLinks

पैरामीटर

पैरामीटर का नाम वैल्यू ब्यौरा
पाथ पैरामीटर
accountId string उपयोगकर्ता लिंक बनाने के लिए खाता आईडी.
profileId string व्यू (प्रोफ़ाइल) आईडी, जिसके लिए उपयोगकर्ता लिंक बनाना है.
webPropertyId string वेब प्रॉपर्टी आईडी, जिसके लिए उपयोगकर्ता लिंक बनाना है.

अनुमति

इस अनुरोध के लिए, नीचे दिए गए दायरे की मदद से अनुमति देना ज़रूरी है (पुष्टि करने और अनुमति देने के बारे में ज़्यादा पढ़ें).

स्कोप
https://www.googleapis.com/auth/analytics.manage.users

अनुरोध का मुख्य भाग

अनुरोध के मुख्य हिस्से में, management.entityUserLink संसाधन दें.

जवाब

अगर यह तरीका काम करता है, तो जवाब के मुख्य हिस्से में management.entityUserLink संसाधन की जानकारी मिलती है.

उदाहरण

ध्यान दें: इस तरीके के लिए दिए गए कोड के उदाहरणों में इसके साथ काम करने वाली सभी प्रोग्रामिंग भाषाएं नहीं दिखाई गई हैं (इसके साथ काम करने वाली भाषाओं की सूची के लिए क्लाइंट लाइब्रेरी वाला पेज देखें).

Java

Java क्लाइंट लाइब्रेरी का इस्तेमाल करता है.

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

/*
 * This request creates a new View (Profile) User Link.
 */

// Construct the user reference object.
UserRef userRef = new UserRef();
userRef.setEmail("liz@gmail.com");

// Construct the permissions object.
Permissions permissions = new Permissions();
List<String> local = Arrays.asList("EDIT", "MANAGE_USERS");
permissions.setLocal(local);

// Construct the body of the request
EntityUserLink body = new EntityUserLink();
body.setPermissions(permissions);
body.setUserRef(userRef);

try {
  analytics.management().profileUserLinks().insert("123456", "UA-123456-1",
      "7654321", body).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 User Permissions Developer Guide for details.
*/

// Create the user reference.
$userRef = new Google_Service_Analytics_UserRef();
$userRef->setEmail('liz@gmail.com');

// Create the permissions object.
$permissions = new Google_Service_Analytics_EntityUserLinkPermissions();
$permissions->setLocal(array('COLLABORATE', 'READ_AND_ANALYZE'));

// Create the view (profile) user link.
$link = new Google_Service_Analytics_EntityUserLink();
$link->setPermissions($permissions);
$link->setUserRef($userRef);

// This request creates a new View (Profile) User Link.
try {
  $analytics->management_profileUserLinks->insert('123456', 'UA-123456-1',
      '756321', $link);
} 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 User Permissions Developer Guide for details.

# This request creates a new Profile User Link.
try:
  analytics.management().profileUserLinks().insert(
      accountId='123456',
      webPropertyId='UA-123456-1',
      profileId='7654321',
      body={
          'permissions': {
              'local': [
                  'EDIT',
                  'MANAGE_USERS'
              ]
          },
          'userRef': {
              'email': 'liz@gmail.com'
          }
      }
  ).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 User Permissions Developer Guide for details.
 */

/*
 * This request creates a new View (Profile) User Link.
 */
function insertProfileUserLink() {
  var request = gapi.client.analytics.management.profileUserLinks.insert(
    {
      'accountId': '123456',
      'webPropertyId': 'UA-123456-1',
      'profileId': '7654321',
      'resource': {
        'permissions': {
          'local': [
            'EDIT',
            'MANAGE_USERS'
          ]
        },
        'userRef': {
          'email': 'liz@gmail.com'
        }
      }
    });
  request.execute(function (response) { // Handle the response. });
}

इसे आज़माएं!

लाइव डेटा पर इस तरीके को कॉल करने और रिस्पॉन्स देखने के लिए, नीचे दिया गया एपीआई एक्सप्लोरर इस्तेमाल करें. इसके अलावा, Standalone Explorer का इस्तेमाल भी किया जा सकता है.