爪哇。 YouTube API。身份验证异常。

发布于 2024-12-27 16:10:27 字数 2896 浏览 1 评论 0原文

我在 youtube api 中遇到“身份验证问题”。获取洞察数据 csv 文件链接。这是我的代码。

package sample.youtube;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import com.google.gdata.client.Query;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.data.youtube.VideoFeed;
import com.google.gdata.util.ServiceException;



public class CSV_Download {

    public static final String UPLOADS_URL = "http://gdata.youtube.com/feeds/api/users/default/uploads"; 
    public static void main(String[] args) {

        YouTubeService service = new YouTubeService("insight api", "dev key");
         Query query = null; 
         try { 
             query = new Query(new URL(UPLOADS_URL));
         } catch (MalformedURLException e) { 
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
         query.setFields("title,entry(title, media:group/media:player)");
         VideoFeed videoFeed = null;
         try { 
             videoFeed = service.query(query, VideoFeed.class); 
         } catch (IOException e) { 
             // TODO Auto-generated catch block 
             e.printStackTrace(); 
         } catch (ServiceException e) { 
             // TODO Auto-generated catch block 
             e.printStackTrace(); 
         }
         System.out.println(videoFeed.getTitle() + ":"); 
         System.out.println(" Link : "+videoFeed.getLink("http://gdata.youtube.com/schemas/2007#insight.views", "text/html") + ":");
    }

}

我的错误信息:

com.google.gdata.util.AuthenticationException:用户身份验证 必需的。需要用户身份验证。

用户 需要身份验证。

错误 401

在 com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600) 在 com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563) 在 com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552) 在 com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530) 在 com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535) 在 com.google.gdata.client.Service.getFeed(Service.java:1135) 处 com.google.gdata.client.Service.getFeed(Service.java:1077) 在 com.google.gdata.client.GoogleService.getFeed(GoogleService.java:662) 在 com.google.gdata.client.Service.query(Service.java:1237) 处 com.google.gdata.client.Service.query(Service.java:1178) 在 Sample.youtube.CSV_Download.main(CSV_Download.java:30) 中的异常 线程“main”java.lang.NullPointerException at Sample.youtube.CSV_Download.main(CSV_Download.java:38)

因此,我在声明 YouTubeService 客户端后在代码中插入了一行(如下所示):

service.setUserCredentials("email_here", "password_here");

现在身份验证错误已结束,代码运行成功。但我得到的链接为空。我没有从 YouTube 开发者论坛收到任何回复。有什么问题吗?

I'm facing 'authentication issue' in youtube api. to get the insight data csv file link. Here is my code.

package sample.youtube;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import com.google.gdata.client.Query;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.data.youtube.VideoFeed;
import com.google.gdata.util.ServiceException;



public class CSV_Download {

    public static final String UPLOADS_URL = "http://gdata.youtube.com/feeds/api/users/default/uploads"; 
    public static void main(String[] args) {

        YouTubeService service = new YouTubeService("insight api", "dev key");
         Query query = null; 
         try { 
             query = new Query(new URL(UPLOADS_URL));
         } catch (MalformedURLException e) { 
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
         query.setFields("title,entry(title, media:group/media:player)");
         VideoFeed videoFeed = null;
         try { 
             videoFeed = service.query(query, VideoFeed.class); 
         } catch (IOException e) { 
             // TODO Auto-generated catch block 
             e.printStackTrace(); 
         } catch (ServiceException e) { 
             // TODO Auto-generated catch block 
             e.printStackTrace(); 
         }
         System.out.println(videoFeed.getTitle() + ":"); 
         System.out.println(" Link : "+videoFeed.getLink("http://gdata.youtube.com/schemas/2007#insight.views", "text/html") + ":");
    }

}

My error message:

com.google.gdata.util.AuthenticationException: User authentication
required. User authentication required.

User
authentication required.

Error 401

at
com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
at
com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
at
com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
at
com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
at
com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
at com.google.gdata.client.Service.getFeed(Service.java:1135) at
com.google.gdata.client.Service.getFeed(Service.java:1077) at
com.google.gdata.client.GoogleService.getFeed(GoogleService.java:662)
at com.google.gdata.client.Service.query(Service.java:1237) at
com.google.gdata.client.Service.query(Service.java:1178) at
sample.youtube.CSV_Download.main(CSV_Download.java:30) Exception in
thread "main" java.lang.NullPointerException at
sample.youtube.CSV_Download.main(CSV_Download.java:38)

So, I inserted a line (given below) into the code just after declaring the YouTubeService client:

service.setUserCredentials("email_here", "password_here");

Now the authentication error is over and code runs successfully. But I'm getting Null as link. I didn't get any response from YouTube developer forum. What can be wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文