2017-07-13 20 views

答えて

0

として簡単ではありません含まれているビデオのタイトルを取得し、印刷したい

これは私のコード

public class MainActivity extends AppCompatActivity { 

Button btn; 
WebView browser; 
EditText url_text; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    openURL(); 
} 

public void openURL(){ 
    btn = (Button) findViewById(R.id.button); 
    url_text =(EditText) findViewById(R.id.editText); 
    browser = (WebView) findViewById(R.id.webView); 

    btn.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String url = "https://www.youtube.com/watch?v=VgC4b9K-gYU"; 

      browser.getSettings().setLoadsImagesAutomatically(true); 
      browser.getSettings().setJavaScriptEnabled(true); 
      browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); 
      browser.loadUrl(url); 
      browser.getSettings().getDisplayZoomControls(); 
     } 
    }); 
} 

}

ですURL。タイトルを取得するには、YouTubeのAPIを使用する必要があります。この情報はJSON応答から得られます。

特定の動画 https://developers.google.com/youtube/v3/code_samples/java

幸運が

0

が使用できるJava ためhttps://developers.google.com/youtube/v3/docs/videos?csw=1

API this

URL: https://www.googleapis.com/youtube/v3/videos?id=7lCDEYXw3mM&key=YOUR_API_KEY 
    &fields=items(id,snippet(channelId,title,categoryId),statistics)&part=snippet,statistics 

Description: This example modifies the fields parameter from example 3 so that in the API response, each video resource's snippet object only includes the channelId, title, and categoryId properties. 

API response: 

{ 
"videos": [ 
    { 
    "id": "7lCDEYXw3mM", 
    "snippet": { 
    "channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw", 
    "title": "Google I/O 101: Q&A On Using Google APIs", 
    "categoryId": "28" 
    }, 
    "statistics": { 
    "viewCount": "3057", 
    "likeCount": "25", 
    "dislikeCount": "0", 
    "favoriteCount": "17", 
    "commentCount": "12" 
    } 
    } 
] 
} 
関連する問題