At first you can create a list of videos, then concatenate creating a StringBuilder
. Behold
List <String> list = new ArrayList <String> ();
list.add("video_codigo_1");
list.add("video_codigo_2");
list.add("video_codigo_3");
list.add("video_codigo_4");
StringBuilder strB = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
if (i < (list.size() - 1))
strB.append(list.get(i)).append(",");
else strB.append(list.get(i));
}
String url = "https://www.googleapis.com/youtube/v3/videos?part=snippet,statistics&id="
+ strB.toString() + "&key={API_KEY}";
See working in IDEONE.
An adaptation for Retrofit,
class SuaActivity extends Activity {
private static final String BASEPATH = "https://www.googleapis.com/youtube/v3/";
private interface API {
@GET("/videos")
void getVideos(@QueryMap Map <String, String>
params, new Callback <String> callback);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
RestAdapter rest = new RestAdapter.Builder().setEndpoint(BASEPATH).build();
API service = rest.create(API.class);
List < String > list = new ArrayList < String > ();
list.add("video_codigo_1");
list.add("video_codigo_2");
list.add("video_codigo_3");
list.add("video_codigo_4");
// concatena as strings separando por virgula
StringBuilder strB = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
if (i < (list.size() - 1))
strB.append(list.get(i)).append(",");
else strB.append(list.get(i));
}
Map <String, String> params = new HashMap <String, String> ();
params.put("part", "snippet,statistics");
params.put("id", strB.toString());
// aqui podes colocar outros parâmetros
service.getVideos(params, new Callback <String> () {
// aqui você faz o tratamento para listar os videos
});
}
}
If there are any further questions regarding the Youtube API parameters, you can check in the documentation.
worked well, had not known to use the string Builder
– Igor Oliveira