Android で新しい Youtube Data API を使用して、特定の ID からビデオ タイトルを取得しようとしています。
https://www.googleapis.com/youtube/v3/videos?id=6DbS1VB8HGo&part=player&key=XXX
ただし、ログインが必要で、エラー コード 401 という応答が返されます。
認証トークンと関係があると推測していますが、プレイリストの更新や削除などのアカウント固有の操作を実行していないため、なぜこれが必要なのかわかりません。私が欲しいのは、タイトルと、おそらくビューの数だけです。
以下は私が使用しているコードです。
public class NetTask extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
HttpClient httpClient = new DefaultHttpClient();
//param[0]= "https://www.googleapis.com/youtube/v3/videos?id=6DbS1VB8HGo&part=player&key=xxyy"
HttpPost httpPost = new HttpPost(params[0]);
HttpResponse response;
try {
response = httpClient.execute(httpPost);
String responseString = EntityUtils.toString(response.getEntity());
JSONObject responseJSON = new JSONObject(responseString);
responseJSON.toString();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}