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?