1

我使用 Youtube gdata api 从 youtube 获取数据。但我在网上遇到错误

YouTubeService 服务 = new YouTubeService("myService");

这是我的代码。

YouTubeService service = new YouTubeService("myService");
Log.i("YouTubeApp", "SelectedProgramID: " + urlLink);
VideoFeed videoFeed = null;
try {
    videoFeed = service.getFeed(new URL(urlLink), VideoFeed.class);
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (ServiceException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

进入 IOException 块

错误

05-03 19:08:54.085: W/System.err(465): java.io.IOException: Hostname <gdata.youtube.com> was not verified
05-03 19:08:54.085: W/System.err(465):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.getSecureSocket(HttpConnection.java:170)
05-03 19:08:54.095: W/System.err(465):  at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection$HttpsEngine.connect(HttpsURLConnection.java:398)
05-03 19:08:54.095: W/System.err(465):  at org.apache.harmony.luni.internal.net.www.protocol.https.HttpsURLConnection.connect(HttpsURLConnection.java:146)
05-03 19:08:54.095: W/System.err(465):  at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:511)
05-03 19:08:54.095: W/System.err(465):  at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
05-03 19:08:54.095: W/System.err(465):  at com.google.gdata.client.Service.getFeed(Service.java:1135)
05-03 19:08:54.095: W/System.err(465):  at com.google.gdata.client.Service.getFeed(Service.java:998)
05-03 19:08:54.095: W/System.err(465):  at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645)
05-03 19:08:54.095: W/System.err(465):  at com.google.gdata.client.Service.getFeed(Service.java:1017)

我添加了这些权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

我已经进口了

"activation.jar", 
"additionnal.jar", 
"gdata-base-1.0.jar", 
"gdata-client-1.0.jar", 
"gdata-core-1.0.jar", 
"gdata-media-1.0.jar", 
"gdata-youtube-2.0.jar", 
"guava-12.0.jar" and 
"mail.jar"

此代码在独立的 java 命令行项目上运行良好。我的代码有什么问题。?有任何想法吗..

谢谢。

4

2 回答 2

1

gDATA无法在ANDROID EMULATOR上运行。它总是返回null

于 2012-06-28T10:22:30.087 回答
0

我在我的 Android 应用程序中遇到了类似的问题。我的应用中有这个 URL:https ://gdata.youtube.com/feeds/api/videos ,我将它替换为http://gdata.youtube.com/feeds/api/videos并且它可以工作。我认为 SSL 有问题。

于 2012-05-26T11:07:31.683 回答