多個用戶端 ID

目前一個用戶端 ID 只能支援一個搜尋功能。如果您想在應用程式中使用多個搜尋功能,請使用多個用戶端 ID。此外,如果您想在應用程式的不同進入點使用相同的搜尋功能,也應為每個進入點使用不同的用戶端 ID,以便區分流量。

針對每項要求,您可以在 GetSearchSuggestionsOptionsGetTrendingSearchesOptionsGetSearchContentOptions 中主動設定用戶端 ID,這個 ID 會覆寫 Info.plist 檔案中的預設用戶端 ID (僅限這項要求)。

Swift

getSearchSuggestions(withOptions:)

Task {
    let options = GetSearchSuggestionsOptions(withTextContext:['Sample Query', 'Another query string'])
    options.clientId = "client id"
    let suggestions = try await searchRuntime.getSearchSuggestions(
            withOptions: options)
}

Objective-C

getSearchSuggestionsWithOptions

  GetSearchSuggestionsOptions *options = [[GetSearchSuggestionsOptions alloc] initWithTextContext: @[@'Sample Query', @'Another query string' ]];
  options.clientId = [NSString stringWithFormat:@"client id"];
  [searchRuntime
      getSearchSuggestionsWithOptions:options
                             completionHandler:^(SearchSuggestions *_Nullable suggestions,
                                                 NSError *_Nullable error) {
                              // error will be not null if there is an error.
                              // On success, suggestions will be non null.
                            }];