Google Drive REST Api download file by its fileId - java

Hello guys I run into a problem. In my application I am storing fileId's of files which user selected before in GoogleDrive file picker. Also I am storing a local copy of that files in device. After each start I want to refresh local files, so I want to download them from drive. But it is not cleare for me, how should i do this.
I saw this documentation, but I can't understand where to get driveService, which used in this code
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);
I don't know what driveService is in this code. (Which class instance) and how do I get it
Help me please, thank you.
P.S.
Sorry for my bad english

you should check the documentation under resumable Media Downloads it might give you some clues.
class CustomProgressListener implements MediaHttpDownloaderProgressListener {
public void progressChanged(MediaHttpDownloader downloader) {
switch (downloader.getDownloadState()) {
case MEDIA_IN_PROGRESS:
System.out.println(downloader.getProgress());
break;
case MEDIA_COMPLETE:
System.out.println("Download is complete!");
}
}
}
OutputStream out = new FileOutputStream("/tmp/driveFile.jpg");
DriveFiles.Get request = drive.files().get(fileId);
request.getMediaHttpDownloader().setProgressListener(new CustomProgressListener());
request.executeMediaAndDownloadTo(out);

BaseClientService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});
You should check this stack answer, maybe it will help you understand it:
How do you create a new Google Drive Service in C# using OAuth

Related

Download youtube videos with Java API?

I found similar questions in Stack Overflow, and I tried few of solutions. All are outdated, so I am raising a new issue.
I followed and tried:
How to download videos from youtube on java?
I gone through the youtube-api, it not providing anything to download as I understand the samples provided in Github.
https://developers.google.com/youtube/v3/code_samples/java
It tried with latest VGet API, it working well but it downloading video(mp4) and audio (webm) separately. How can I combine both?
import com.github.axet.vget.VGet;
public class YoutubeDownloadTool {
public static void main(String[] args) {
try {
String url = "https://www.youtube.com/watch?v=7lFhwXeSidQ";
String path = "D:\\videos";
VGet v = new VGet(new URL(url), new File(path));
v.download();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Downloading of videos is not supported in Youtube API. It is in fact prohibited. Under Terms of Service - II. Prohibitions it is mentioned that:
Prohibited
store copies of YouTube audiovisual content
use the YouTube API intentionally to encourage or promote copyright infringement or the exploitation of copyright-infringing materials;
Also, this SO thread states that is explicitly mentioned in Youtube Page terms
"You shall not download any Content unless you see a “download” or similar link displayed by YouTube on the Service for that Content. You shall not copy, reproduce, distribute, transmit, broadcast, display, sell, license, or otherwise exploit any Content for any other purposes without the prior written consent of YouTube or the respective licensors of the Content "

Java, Dropbox : Get access token without copy pasting by user.

I am working on a Spring-MVC application and I would like to integrate Dropbox functionality into it. As I read the examples, I saw that there is some code which I can use. But this involves the user copy pasting the access token, which is not applicable in real world applications, plus I cannot find a way to set the redirect URL when authentication is complete. What changes should I make so the code does not need to copy pasted, but can be retrieved directly.
Code :
public void connectToDropbox() {
DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);
DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
Locale.getDefault().toString());
DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
// Have the user sign in and authorize your app.
String authorizeUrl = webAuth.start();
System.out.println("1. Go to: " + authorizeUrl);
System.out.println("2. Click \"Allow\" (you might have to log in first)");
// No, I dont want to copy the authorization code.
System.out.println("3. Copy the authorization code.");
String code = null;
try {
code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();
} catch (IOException e) {
e.printStackTrace();
}
Controller code :
#RequestMapping(value = "/logindropbox")
public String loginIntoDropbox(){
ConnectDropbox connectDropbox = new ConnectDropbox();
connectDropbox.connectToDropbox();
return "rediect:/dashboard";
}
There was only one answer I could find on SO, but that was of no use. Any help would be nice. Thanks a lot. :-)
[Cross-linking for reference: https://www.dropboxforum.com/hc/communities/public/questions/203308909-Dropbox-authentication-without-copy-pasting-the-access-token-manually-in-Java- ]
The Dropbox Java Core SDK tutorial does use the flow where the user copies and pastes the authorization code manually. This is done using the provided DbxWebAuthNoRedirect class.
For apps where a redirect URI can be used to deliver the authorization code automatically, you'll want to use the DbxWebAuth class instead. The documentation has some sample code:
https://dropbox.github.io/dropbox-sdk-java/api-docs/v1.7.x/com/dropbox/core/DbxWebAuth.html
There's also a "web-file-browser" sample app included with the SDK download that uses DbxWebAuth.

remote FileChooser using OtrosVFSBrowser

I'm trying to do a remote filechooser. I read a lot of information but I don't get it.
The best site I've seen is (https://code.google.com/p/otrosvfsbrowser/) because is exactly what I want but I don't fine more information. Are Someone of you using this tool? where are any example code?
I already use JSCH library to transfer via SFTP, but I want a tool to choose the remote path.
I'm starting in Java. sorry for my English.
You can check example code on Usage page
You can just create dialog and register action on approve:
JOtrosVfsBrowserDialog jOtrosVfsBrowserDialog = new JOtrosVfsBrowserDialog();
Action a = new AbstractAction("Select file") {
#Override
public void actionPerformed(ActionEvent actionEvent) {
if (JOtrosVfsBrowserDialog.ReturnValue.Approve.equals(jOtrosVfsBrowserDialog.showOpenDialog(TestDialog.this,"title"))){
String friendlyUrl = jOtrosVfsBrowserDialog.getSelectedFile().getName().getFriendlyURI();
}
}
};

URL code assistance please short code (Newbie Java programmer)

I'm using NetBeans and trying to make a Jbutton play this .wav file that I have located in the build/classes/shadow part of my project. I want the .Jar to build with the .wav file so I could download the .Jar file on another computer and press the button and the music will play. The music is not locating or starting I'm not sure which it is, also please be easy on the terminology I am very very new.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:File Clap = new File("sanic.WAV");
display.setText("cum on step it up!!!");
}
public static void startMusic() {
{
try{
URL url = Shadow.class.getClassLoader().getResource("sanic.wav");
play(); // NetBeans says it cannot find the symbol for play.
}catch(Exception e){
}
}
}
I'm not sure in what part of your code are you using your URL... But I'd suggest you to use AudioInputStream...
Regarding the problem finding the file... I had implemented something similar some time ago, while checking the code I have in my HDD, I found that this made it for me:
URL url = Shadow.class.getResource(myfile.wav);
But nowadays, I prefer working with this:
InputStream resourceAsStream = Shadow.class.getResourceAsStream(myfile.wav);
Hope it helps for what you need to do.
Regards and... happy coding :)

How can I obtain my profile picture from Google Talk using smack API?

How can I get my profile picture from my Google Talk profile using Smack API or any other API.
I tried using VCards but it does not work. I obtain only an XML representation of the users profile: FirstName LastName.
I found a solution. It seems that I cannot take the avatar picture only on the roster listener. This means that only when the presence changes you can see user's Presence.Type and can get it's avatar, but other data about his profile cannot be taken. If anyone knows why or has a solution I would be very happy to see what he has in mind.
try this it work complete.
try {
vCard.load(connection, entry.getUser());
vCard.getExtensions();
byte[] b = vCard.getAvatar();
Bitmap avatar = BitmapFactory.decodeByteArray(vCard.getAvatar(), 0, b.length);
} catch (Exception e) {
Log.e("EXP-Image", "Not valid code");
}

Categories