Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bạn có thể sử dụng tài khoản dịch vụ trong Trình kết nối cộng đồng để
quản lý quyền truy cập tài nguyên. Một trường hợp sử dụng phổ biến là uỷ quyền truy cập vào
mà người dùng không thể truy cập bằng thông tin đăng nhập của riêng họ.
Bạn có thể hợp nhất thông tin thanh toán để truy cập vào dữ liệu.
Bạn có thể triển khai lớp kiểm soát truy cập của riêng mình trong trình kết nối.
Bạn có thể uỷ quyền truy cập vào dữ liệu hoặc tài nguyên mà thông tin xác thực của người dùng
không có quyền truy cập vào.
Các bước triển khai
Tạo tài khoản dịch vụ cho nền tảng mà bạn đang tìm nạp dữ liệu.
Cấp các quyền cần thiết cho tài khoản dịch vụ để tài khoản dịch vụ có thể truy cập
các tài nguyên cần thiết.
Lưu trữ thông tin đăng nhập của tài khoản dịch vụ trong tập lệnh của trình kết nối
các thuộc tính.
Trong quá trình thực thi trình kết nối, hãy sử dụng thông tin đăng nhập đã lưu trữ để tìm nạp thông tin cần thiết
.
Không bắt buộc: Triển khai logic kiểm soát quyền truy cập để lọc dữ liệu.
Ví dụ: Truy cập vào BigQuery bằng các Dịch vụ nâng cao của Looker Studio và tài khoản dịch vụ
Bạn đang xây dựng một giải pháp trong đó người dùng sẽ xây dựng trang tổng quan từ
Bảng BigQuery. Nếu người dùng sử dụng trình kết nối BigQuery của Looker Studio, họ sẽ
cần quyền đọc bảng BigQuery. Họ cũng sẽ yêu cầu một tài khoản thanh toán
dành cho Google Cloud Platform (GCP). Các bước sau đây minh hoạ cách sử dụng
tài khoản dịch vụ của Google để tổng hợp thông tin thanh toán và uỷ quyền truy cập vào dữ liệu BigQuery.
Đảm bảo tài khoản dịch vụ có thể tạo công việc trong BigQuery và xem dữ liệu
bảng bắt buộc. Xem Kiểm soát quyền truy cập vào BigQuery để biết chi tiết.
Đối với hàm getData, hãy xác thực tài khoản dịch vụ và tạo
mã truy cập. Đặt phạm vi của OAuth2 thành
https://www.googleapis.com/auth/bigquery.readonly.
Trả về mã truy cập cùng các mục cấu hình khác trong phản hồi getData.
Sau đây là ví dụ hoàn chỉnh về mã trình kết nối:
main.js
varcc=DataStudioApp.createCommunityConnector();varscriptProperties=PropertiesService.getScriptProperties();functionisAdminUser(){returntrue;}functiongetAuthType(){varAuthTypes=cc.AuthType;returncc.newAuthTypeResponse().setAuthType(AuthTypes.NONE).build();}functiongetConfig(request){varconfig=cc.getConfig();config.newInfo().setId('generalInfo').setText('This is an example connector to showcase row level security.');returnconfig.build();}functiongetFields(){varfields=cc.getFields();vartypes=cc.FieldType;varaggregations=cc.AggregationType;fields.newDimension().setId('region').setName('Region').setType(types.TEXT);fields.newMetric().setId('sales').setName('Sales').setType(types.NUMBER).setAggregation(aggregations.SUM);fields.newDimension().setId('date').setName('Date').setType(types.YEAR_MONTH_DAY);returnfields;}functiongetSchema(request){return{schema:getFields().build()};}varSERVICE_ACCOUNT_CREDS='SERVICE_ACCOUNT_CREDS';varSERVICE_ACCOUNT_KEY='private_key';varSERVICE_ACCOUNT_EMAIL='client_email';varBILLING_PROJECT_ID='project_id';/** * Copy the entire credentials JSON file from creating a service account in GCP. */functiongetServiceAccountCreds(){returnJSON.parse(scriptProperties.getProperty(SERVICE_ACCOUNT_CREDS));}functiongetOauthService(){varserviceAccountCreds=getServiceAccountCreds();varserviceAccountKey=serviceAccountCreds[SERVICE_ACCOUNT_KEY];varserviceAccountEmail=serviceAccountCreds[SERVICE_ACCOUNT_EMAIL];returnOAuth2.createService('RowLevelSecurity').setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth').setTokenUrl('https://accounts.google.com/o/oauth2/token').setPrivateKey(serviceAccountKey).setIssuer(serviceAccountEmail).setPropertyStore(scriptProperties).setCache(CacheService.getScriptCache()).setScope(['https://www.googleapis.com/auth/bigquery.readonly']);}varBASE_SQL='SELECT d.region, d.sales, d.date '+'FROM `datastudio-solutions.row_level_security.data` d '+'INNER JOIN `datastudio-solutions.row_level_security.access` a '+'ON d.region = a.region '+'where a.email=@email';functiongetData(request){varaccessToken=getOauthService().getAccessToken();varserviceAccountCreds=getServiceAccountCreds();varbillingProjectId=serviceAccountCreds[BILLING_PROJECT_ID];varemail=Session.getEffectiveUser().getEmail();varbqTypes=DataStudioApp.createCommunityConnector().BigQueryParameterType;returncc.newBigQueryConfig().setAccessToken(accessToken).setBillingProjectId(billingProjectId).setUseStandardSql(true).setQuery(BASE_SQL).addQueryParameter('email',bqTypes.STRING,email).build();}
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[],[]]