Question

I'm trying to use Deezer's Android SDK to do searches. However, the search results are always empty. Here's how I'm doing:

private final static String[] PERMISSIONS = new String[]{};
private DeezerConnect deezerConnect = new DeezerConnectImpl(DEEZER_APP_ID);
RequestListener handler = new CustomDeezerRequestHandler();

// User login
deezerConnect.authorize(MainActivity.this, PERMISSIONS, new MyDialogHandler());

// When the login is completed:
// Search request
DeezerRequest request = new DeezerRequest("/search/artist?q=radiohead");
deezerConnect.requestAsync(request, handler);

API result:

{"data":[],"total":0}
Was it helpful?

Solution

The DeezerRequest object performs severall operations on the API path it's given (in your case "/search/artist?q=radiohead"). Among those operations, query parameters are reset to be compliant with the Deezer JSON API.

TO add your own parameters in such a request, a mechanism is provided in different constructors of the DeezerRequest object. Quoting from the SDK documentation :

public DeezerRequest(String deezerServicePath,Bundle params)

DeezerRequest constructor using the GET Method.

Parameters:

  • deezerServicePath - Path to service. Matches the url of the request minus the protocol and server host name part.
  • params - Parameters passed to the service request. Parameters will be added automatically via get or post.

So in your case, you should use the following method to create your request :

    // Search request
    Bundle bundle = new Bundle();
    bundle.putString("q", "radiohead");
    DeezerRequest request = new DeezerRequest("/search/artist", bundle);
    mDeezerConnect.requestAsync(request, this);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top