अपने खाते का ऐक्सेस कंट्रोल करना

Merchant Center खाते का ऐक्सेस किसके पास है और उसका ऐक्सेस लेवल क्या है, यह कंट्रोल करने के लिए Merchant Center खाते के लिए उपलब्ध एपीआई का इस्तेमाल किया जा सकता है.

User वह व्यक्ति होता है जिसके पास आपके Merchant Center खाते का ऐक्सेस होता है. Merchant Center API का इस्तेमाल करके, अपने खाते में उपयोगकर्ताओं को देखा जा सकता है, जोड़ा जा सकता है, और हटाया जा सकता है.

अपने खाते में उपयोगकर्ता जोड़ना

किसी उपयोगकर्ता को जोड़ने के लिए, accounts.users.create तरीका इस्तेमाल करें. साथ ही, User के access_rights फ़ील्ड में, उपयोगकर्ता का ऐक्सेस लेवल डालें.

यहां दिए गए अनुरोध के सैंपल में, STANDARD और PERFORMANCE_REPORTING अनुमतियों के साथ नया उपयोगकर्ता जोड़ने का तरीका बताया गया है:

POST https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}/users?userId={USER_EMAILID}

{
  "accessRights": [
    "STANDARD",
    "PERFORMANCE_REPORTING"
  ],
  "name": "{NAME}"
}

इनकी जगह ये डालें:

  • {ACCOUNT_ID}: आपके Merchant Center खाते का यूनीक आइडेंटिफ़ायर.
  • {USER_EMAILID}: उस उपयोगकर्ता का ईमेल पता जिसे आपको जोड़ना है.
  • {NAME}: उपयोगकर्ता के रिसॉर्स का नाम, accounts/{ACCOUNT_ID}/user/{EMAIL_ADDRESS} फ़ॉर्मैट में होना चाहिए.

अनुरोध पूरा होने के बाद, यह रिस्पॉन्स मिलता है:

{
  "name": "accounts/{ACCOUNT_ID}/users/{USER_EMAILID}",
  "state": "PENDING",
  "accessRights": [
    "STANDARD",
    "PERFORMANCE_REPORTING"
  ]
}

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

यहां दिए गए सैंपल में, अपने खाते में किसी उपयोगकर्ता को जोड़ने के लिए, CreateUserRequest तरीके का इस्तेमाल करने का तरीका बताया गया है.

Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.AccessRight;
import com.google.shopping.merchant.accounts.v1beta.CreateUserRequest;
import com.google.shopping.merchant.accounts.v1beta.User;
import com.google.shopping.merchant.accounts.v1beta.UserServiceClient;
import com.google.shopping.merchant.accounts.v1beta.UserServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to create a user for a Merchant Center account. */
public class CreateUserSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  public static void createUser(Config config, String email) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    UserServiceSettings userServiceSettings =
        UserServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates parent to identify where to insert the user.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (UserServiceClient userServiceClient = UserServiceClient.create(userServiceSettings)) {

      CreateUserRequest request =
          CreateUserRequest.newBuilder()
              .setParent(parent)
              // This field is the email address of the user.
              .setUserId(email)
              .setUser(
                  User.newBuilder()
                      .addAccessRights(AccessRight.ADMIN)
                      .addAccessRights(AccessRight.PERFORMANCE_REPORTING)
                      .build())
              .build();

      System.out.println("Sending Create User request");
      User response = userServiceClient.createUser(request);
      System.out.println("Inserted User Name below");
      // The last part of the user name will be the email address of the user.
      // Format: `accounts/{account}/user/{user}`
      System.out.println(response.getName());
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // The email address of this user.
    String email = "testUser@gmail.com";

    createUser(config, email);
  }
}

उन उपयोगकर्ताओं को देखना जिनके पास आपके खाते का ऐक्सेस है

आपके खाते का ऐक्सेस रखने वाले सभी उपयोगकर्ताओं को देखने के लिए, accounts.users.list तरीका अपनाएं.

यहां दिए गए सैंपल में दिखाया गया है कि किसी खाते के सभी उपयोगकर्ताओं की सूची बनाने के लिए, ListUsersRequest तरीके का इस्तेमाल कैसे किया जा सकता है.

Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.ListUsersRequest;
import com.google.shopping.merchant.accounts.v1beta.User;
import com.google.shopping.merchant.accounts.v1beta.UserServiceClient;
import com.google.shopping.merchant.accounts.v1beta.UserServiceClient.ListUsersPagedResponse;
import com.google.shopping.merchant.accounts.v1beta.UserServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to list all the users for a given Merchant Center account. */
public class ListUsersSample {

  private static String getParent(String accountId) {
    return String.format("accounts/%s", accountId);
  }

  public static void listUsers(Config config) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    UserServiceSettings userServiceSettings =
        UserServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates parent to identify the account from which to list all users.
    String parent = getParent(config.getAccountId().toString());

    // Calls the API and catches and prints any network failures/errors.
    try (UserServiceClient userServiceClient = UserServiceClient.create(userServiceSettings)) {

      // The parent has the format: accounts/{account}
      ListUsersRequest request = ListUsersRequest.newBuilder().setParent(parent).build();

      System.out.println("Sending list users request:");
      ListUsersPagedResponse response = userServiceClient.listUsers(request);

      int count = 0;

      // Iterates over all rows in all pages and prints the user
      // in each row.
      // `response.iterateAll()` automatically uses the `nextPageToken` and recalls the
      // request to fetch all pages of data.
      for (User element : response.iterateAll()) {
        System.out.println(element);
        count++;
      }
      System.out.print("The following count of elements were returned: ");
      System.out.println(count);
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    listUsers(config);
  }
}

किसी खाते के लिए एक उपयोगकर्ता को वापस लाना

यहां दिए गए सैंपल में, किसी खाते के लिए उपयोगकर्ता की जानकारी पाने के लिए, GetUserRequest तरीके का इस्तेमाल करने का तरीका बताया गया है.

Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.GetUserRequest;
import com.google.shopping.merchant.accounts.v1beta.User;
import com.google.shopping.merchant.accounts.v1beta.UserName;
import com.google.shopping.merchant.accounts.v1beta.UserServiceClient;
import com.google.shopping.merchant.accounts.v1beta.UserServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to get a single user for a given Merchant Center account. */
public class GetUserSample {

  public static void getUser(Config config, String email) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    UserServiceSettings userServiceSettings =
        UserServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates user name to identify user.
    String name =
        UserName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setEmail(email)
            .build()
            .toString();

    // Calls the API and catches and prints any network failures/errors.
    try (UserServiceClient userServiceClient = UserServiceClient.create(userServiceSettings)) {

      // The name has the format: accounts/{account}/users/{email}
      GetUserRequest request = GetUserRequest.newBuilder().setName(name).build();

      System.out.println("Sending Get user request:");
      User response = userServiceClient.getUser(request);

      System.out.println("Retrieved User below");
      System.out.println(response);
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // The email address of this user. If you want to get the user information
    // Of the user making the Content API request, you can also use "me" instead
    // Of an email address.
    String email = "testUser@gmail.com";

    getUser(config, email);
  }
}

किसी खाते से उपयोगकर्ता को हटाना

अपने खाते से किसी उपयोगकर्ता को हटाने के लिए, accounts.users.delete के तरीके का इस्तेमाल करके अनुरोध करें.

नीचे दिए गए सैंपल में, किसी खाते से उपयोगकर्ता को हटाने के लिए, DeleteUserRequest तरीके का इस्तेमाल करने का तरीका बताया गया है.

Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.DeleteUserRequest;
import com.google.shopping.merchant.accounts.v1beta.UserName;
import com.google.shopping.merchant.accounts.v1beta.UserServiceClient;
import com.google.shopping.merchant.accounts.v1beta.UserServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to delete a user for a given Merchant Center account. */
public class DeleteUserSample {

  public static void deleteUser(Config config, String email) throws Exception {

    // Obtains OAuth token based on the user's configuration.
    GoogleCredentials credential = new Authenticator().authenticate();

    // Creates service settings using the credentials retrieved above.
    UserServiceSettings userServiceSettings =
        UserServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates user name to identify the user.
    String name =
        UserName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setEmail(email)
            .build()
            .toString();

    // Calls the API and catches and prints any network failures/errors.
    try (UserServiceClient userServiceClient = UserServiceClient.create(userServiceSettings)) {
      DeleteUserRequest request = DeleteUserRequest.newBuilder().setName(name).build();

      System.out.println("Sending Delete User request");
      userServiceClient.deleteUser(request); // no response returned on success
      System.out.println("Delete successful.");
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    // The email address of this user. If you want to delete the user information
    // Of the user making the Content API request, you can also use "me" instead
    // Of an email address.
    String email = "testUser@gmail.com";

    deleteUser(config, email);
  }
}

किसी उपयोगकर्ता का ऐक्सेस लेवल बदलना

किसी उपयोगकर्ता का ऐक्सेस लेवल बदलने के लिए, नए ऐक्सेस लेवल के साथ accounts.users.patch तरीका कॉल करें.

नीचे दिए गए सैंपल में, किसी उपयोगकर्ता को किसी खाते का एडमिन बनाने के लिए, UpdateUserSample तरीके का इस्तेमाल करने का तरीका बताया गया है.

Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.protobuf.FieldMask;
import com.google.shopping.merchant.accounts.v1beta.AccessRight;
import com.google.shopping.merchant.accounts.v1beta.UpdateUserRequest;
import com.google.shopping.merchant.accounts.v1beta.User;
import com.google.shopping.merchant.accounts.v1beta.UserName;
import com.google.shopping.merchant.accounts.v1beta.UserServiceClient;
import com.google.shopping.merchant.accounts.v1beta.UserServiceSettings;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;

/** This class demonstrates how to update a user to make it an admin of the MC account. */
public class UpdateUserSample {

  public static void updateUser(Config config, String email, AccessRight accessRight)
      throws Exception {

    GoogleCredentials credential = new Authenticator().authenticate();

    UserServiceSettings userServiceSettings =
        UserServiceSettings.newBuilder()
            .setCredentialsProvider(FixedCredentialsProvider.create(credential))
            .build();

    // Creates user name to identify user.
    String name =
        UserName.newBuilder()
            .setAccount(config.getAccountId().toString())
            .setEmail(email)
            .build()
            .toString();

    // Create a user with the updated fields.
    User user = User.newBuilder().setName(name).addAccessRights(accessRight).build();

    FieldMask fieldMask = FieldMask.newBuilder().addPaths("access_rights").build();

    try (UserServiceClient userServiceClient = UserServiceClient.create(userServiceSettings)) {

      UpdateUserRequest request =
          UpdateUserRequest.newBuilder().setUser(user).setUpdateMask(fieldMask).build();

      System.out.println("Sending Update User request");
      User response = userServiceClient.updateUser(request);
      System.out.println("Updated User Name below");
      System.out.println(response.getName());
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    String email = "testUser@gmail.com";
    // Give the user admin rights. Note that all other rights, like
    // PERFORMANCE_REPORTING, would be overwritten in this example
    // if the user had those access rights before the update.
    AccessRight accessRight = AccessRight.ADMIN;

    updateUser(config, email, accessRight);
  }
}

सुपर एडमिन, एडमिन, और स्टैंडर्ड ऐक्सेस के बीच तुलना

Business Manager के सुपर एडमिन ऐक्सेस वाले उपयोगकर्ताओं को Merchant Center से नहीं हटाया जा सकता. सुपर एडमिन ऐक्सेस के बारे में ज़्यादा जानने के लिए, सुपर एडमिन के तौर पर अपना कारोबार मैनेज करना लेख पढ़ें.

खाते का डेटा लिखने वाले कुछ तरीकों के लिए, एडमिन ऐक्सेस की ज़रूरत होती है. हर तरीके के लिए ज़रूरी ऐक्सेस लेवल जानने के लिए, रेफ़रंस दस्तावेज़ देखें.

अगर कोई ऐक्सेस लेवल तय नहीं किया गया है, तो स्टैंडर्ड ऐक्सेस वाले तरीके का इस्तेमाल किया जा सकता है.

आगे क्या करना है