All Products
Search
Document Center

Obtain recommendation results

Last Updated: Apr 01, 2021

Parameters

Parameter

Type

Description

Required

Remarks

userId

String

The ID of the user who requires the recommendation service.

You cannot leave this parameter and the imei parameter empty at the same time.

If the user ID does not exist in the user table, personalized recommendation cannot be implemented.

imei

String

Android operating system: an IMEI value generated by using the MD5 message-digest algorithm.

iOS operating system: an IDFA value generated by using the MD5 message-digest algorithm.

No

1. This parameter is required for users who do not have an account.

2. If information such as the MAC address or device number is invalid, the internal user persona information cannot be used. Only the recommendation blocking feature can be used.

3. The value of this parameter is a 32-bit MD5 value.

returnCount

Integer

The number of recommendation entries returned for a single request.

Yes

The recommended value is 20.

ip

String

The IP address.

No

-

sceneId

String

The ID of the scene to which items are launched.

No

The default value is 1. Use the actual scene ID that is contained in the uploaded scene data.

items

String

The baseline items.

No

This parameter is used only for the scenes with service type set to related recommendations. Specify this parameter in the format of itemId:itemType,itemId:itemType.

Common errors that occur when you use server SDKs to obtain recommendation results

Causes of an empty result:

1. Values of request parameters are invalid. When you specify Scenario ID, make sure that the value you entered exists in the reported data. When you specify Test User, if the value you entered does not exist in the user table, a new user is created. The value of Recommended Commodities must be less than the number of items that can be recommended in the scene. Note: In the recommendation results that are obtained by using a server SDK, the maximum number of recommendation items is 50. In a scene with service type set to related recommendations, you must also specify Existing Commodity in the format of item_id:item_type, as shown in the following figure.2. The number of items that meet recommendation conditions is small. As a result, after the Request parametersrecommendation blocking feature is enabled, no available items can be pushed to users and the result is empty.

Sample code

package com.aliyun.airec;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.airec.model.v20181012.RecommendRequest;
import com.aliyuncs.airec.model.v20181012.RecommendResponse;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class Recommend {
    private static final String accessKeyId = "your access key";
    private static final String accessKeySecret = "your access key secret";

    public static void main(String args[]) {
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "Airec", "airec.cn-hangzhou.aliyuncs.com");

        DefaultAcsClient client = new DefaultAcsClient(profile);

        RecommendRequest request = new RecommendRequest();

        //The following three parameters are required.
        request.setInstanceId("airec-xxx");
        request.setReturnCount(10);
        request.setSceneId("scene_id");

        //At least one of the following parameters needs to be reported(imei/user_id).
        request.setUserId("0");
        request.setImei("0");

        // Optional if the service type is related recommendations.
        //request.setItems("88:article,33:image");

        request.setAcceptFormat(FormatType.JSON);

        try {
            RecommendResponse response = client.getAcsResponse(request);

            for (RecommendResponse.ResultItem item : response.getResult()) {
                System.out.println(item.getItemId());
                System.out.println(item.getItemType());
                System.out.println(item.getTraceId());
                System.out.println(item.getTraceInfo());
                System.out.println(item.getMatchInfo());
                System.out.println(item.getWeight());
                System.out.println(item.getPosition());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}