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
On microsoft graph explorer i am able to retrieve the excel file easily but when trying on the "active-directory-android-native-v2-master" sample code, it returns 404.
On the the other hand, next line works and retrieves my information correctly
final static String MSGRAPH_URL = "https://graph.microsoft.com/v1.0/me";
I added all required permissions, got the client ID, run all the sample instructions, read the documentation + stack over flow.
I thought it might be because the link was not coded correctly so i modified the callGraphAPI() method to include:
Uri.Builder builder = new Uri.Builder();
builder.
scheme("https").
authority("graph.microsoft.com").
appendPath("v1.0").
appendPath("drives").
appendPath(MY_DRIVE).
appendPath("items").
appendPath(FILE_ID).
appendPath("workbook");
String url = builder.build().toString();
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET,url/*MSGRAPH_URL*/,
parameters,new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
but still the same response.
I came across the next stack overflow answer
404 file not found error when using microsoft graph api
And thought it might be the answer but then seen the question was old and another answer mentioned it is not longer correct.
appreciate any help.
It seems i was not aware using sample code for the V2 (active-directory-android-native-v2-master) while the graph explorer (which was working) used V1.
There is a great "getting started" tutorial for the V1 sample code (active-directory-android-master) here:
https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-v1-android
Sample code seems quite the same only for V1.
When using the tutorial, i needed to find the required permissions for the command i was trying to use, in addition to the one mentioned at the tutorial.
I used the next link to get the permissions for the items:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/shares_get
I also added the permissions mentioned at the Graph Exlorer since as noted, the command i was trying to use worked there.
Since the permissions at the Azure site was not written the same (e.g. Files.Read is written as "Read user files") i used the next link to translate:
https://developer.microsoft.com/en-us/graph/docs/concepts/permissions_reference
Luckily i did not need to use any admin permissions, which would have complicated the registration to the app
Hopes this helps any struggled newbie like me :)
If anything from what i wrote not correct or you think i should add something, please let me know at the comments below and i will try to update
BTW - i used the Graph Exlorer to detect the files & Drive ID items i needed
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am new in Android.
I was working for uploading Image/Video on Twitter. I used the twitpic for this purpose.
I first sent image to twitpic and then updated the status in twitter with url of the tweet.
Image is successfully loading as per my selection from gallery.
But I am stuck in uploading video on Twitter. As there is option of twitpic or twitvid for uploading video. But there is no such type of code or sdk given. So confused that how to do this, which classes has to be used.
I need a sample code for uploading video.
Was stuck on this for a while myself as well (not a lot of examples around) and found a non-working example here on SO which I've managed to hammer into shape...
First you'll need the twitvid Java API
1 download the jar file (I used twitvid-java 1.6.1)
2 put it in your "libs" folder
3 right-click on your project and go to "properties"
4 select "Java build path" and include the jar ("libraries" tab) and make sure it's built ("order and export" tab)
The code that follows assumes you've already made a token with the regular twitter4j methods:
private void postToTwitvid(String videoPath){
AccessToken token = mTwitter.getAccessToken();
Values values = new Values();
values.setSession(new Session());
TwitvidApi api = new TwitvidApi(values);
api.setSecureUrlEnabled(false);
Session session;
try {
session = api.authenticate(new TwitterAuthPack.Builder()
.setConsumerKey(twitter_consumer_key)
.setConsumerSecret(twitter_secret_key)
.setOAuthToken(token.getToken())
.setOAuthTokenSecret(token.getTokenSecret())
.build());
api.getValues().setSession(session);
final UploadHelper helper = new UploadHelper(api);
File file=new File(videoPath);
TwitvidPost twitvidPost = new TwitvidPost.Builder()
.setFile(file).setChunkSize(10485760)
.setMessage("Twitvid test")
.setPostToTwitter(true)
.create();
try {
if (helper.upload(twitvidPost))
{
Toast.makeText(TwitterShare.this, "Posted on Twitter and Twitvid", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(TwitterShare.this, "Post failed", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}
}
The token depends on how you've implemented the regular posting to twitter, just include yours.
Hope this helps!
PS: I had to force the UI thread to accept network connections to make this work
(My first answer! w00t!)
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");
}
I'm doing a website for a family member's wedding. A feature they requested was a photo section where all the guests could go after the wedding and upload their snaps. I said this was a stellar idea and I went off to build it.
Well there's just the one problem: logistics. Upload speeds are slow and photos from modern cameras are huge (2-5+Megs).
I will only need ~800px wide images and some of them might require rotating so ideally I'm looking about using a client-side editor to do three things:
Let users pick multiple files
Let them rotate some images so they're the right way up
Resize them and then upload
And in my dream world, it'd be free and open source. Any ideas?
Just a reminder: this is something the guests have to use. Some of them will be pretty computer savvy but others will be almost completely illiterate. Installing desktop apps isn't really an option. And I assume 98% of them have Flash and Java installed.
Edit: I'd prefer a Flash/Java option over SilverLight, not least because it has a smaller install rate at the moment, but also because I'm on Linux and I'd like to test it =)
The most common solution for this is a java applet, although most of them are not free. Examples:
http://www.jumploader.com/
http://www.aurigma.com/Products/ImageUploader/OnlineDemo.aspx
http://www.javaatwork.com/java-upload-applet/details.html
JUpload, mentioned by ScArcher2
I have had good luck with Gallery. It is free, open source, and has all the features you mentioned.
It will allow your users to upload photos without any intervention from you.
Another option could be to allow people to upload their photos to whatever service they're used to using (flickr, google, smugmug, or any other), and just accept a username for that service, or a URL for the folder.
Then you can have your application grab a copy of those pictures to store locally with a consistent interface.
I've used swfupload quite a bit. It's pretty awesome: http://www.swfupload.org/
If you are doing this with Flash and using Flickr, then I would check out the AS3 Flickr library:
http://code.google.com/p/as3flickrlib/
which has support for uploading images.
Upload requires authentication. The library also contains a Flex based control for handling this:
http://www.mikechambers.com/blog/2008/08/12/flex-based-flickr-api-authorization-control/
(the rest of the library is ActionScript 3 and can be used in Flex or Flash.
Probably the easiest solution is to just have the images uploaded to Flickr, edited in Picnik (built into Flickr now), and then loaded onto the users site using either the Flickr RSS feeds or APIs:
http://www.flickr.com/help/picnik/
http://www.flickr.com/services/api/
hope that helps...
mike chambers
mesh#adobe.com
I'd use an applet. You could do the resizing of the pictures and rotating on the client side.
It looks like JUpload may do this for you.
Picasa is a pretty great/free photo management app. It let's you do some pretty impressive editing, and has upload capabilities, though I can't remember if it will upload to anywhere, or just certain popular sites (like Flickr).
You could use Silverlight or Flash or some custom plugin to allow managed uploads, where you can display a progress bar for example. There isn't much you can do about upload speeds but you can at least show them progress while it's going on.
I don't know of any canned upload programs you can use but it shouldn't be too hard to make one (unless you don't know Flash or Silverlight).
How about using PhotoShop Online It allows you to edit photos with a web based editor and offers 2GB of storage. I've not used it myself so don't know if it allows for multiple users to access the same account though
Out of curiosity, on what web stack is this to run? LAMP? 2k3+IIS? etc etc? Many of the open source solutions out there are cross-platform but others are not...
Is E-mailing the photo in an available option?
Most people who want to share photos probably already know how to send photos in email. And most email clients has already solved the problems of file uploading.
Just setup one gmail/whatevermail account and have your website poll the inbox.
It's something like what TwitPic does for twitter but your requirements seem to be more simpler than that.
Personally most users don't understand DPI and their images even trimmed down end up larger than the php.ini for most hosting companies allow.
I'm not sure how much control you want to give them or how you want the public side to behave.
I'd suggest using a dropbox FTP application such as http://etonica.com/dropbox/index.html (tango dropbox) It's free to your clients and you only have to pay for your version so you can set up the FTP information and secure it.
I'd have them download something link paint.net (which is FREE) have them edit the photos to the proper size and then just drag and drop them to this application. it's easy and doesn't require php.ini to be modified.
You could also use something like slideshowpro's director application.
I completly agree with zigdon, allow different sites, but only pick up photos from the web. I you still want to allow uploads, and put a cap on size.
Now, if you want to throw yourself into something big, I would suggest putting a cap on size, and then using JQuery (or other library) to work with the images.
Just my 2 cents
You could also have them email the pictures to picasa. Picasa web has a feature where you can send images to a "secret" email that will post them to a picasa account. Set up a picasa account, distribute the "secret" email, and wait for all the pictures to show up.
Going the Flickr route is easy and will work well.
If you want to go more advanced, I'd recommend snipshot or picknik (Flickr uses it). Both are free to use and have APIs to use.
I am currently required to implement the similar requirement as Oli.
I believe Facebook.com use java applet of some sort, and it work pretty well but I am not sure if the applet available as OSS. I am going to look into JUpload suggested by ScArcher2.
If you guy no of any other good applet please keep it coming.
I'd highly suggest using FileBrowser by Lussomo. It's as easy as 'drag and drop' :D
I've used it for my game development team where we had a raw dump of over 200 concept art images, and we simply extracted FileBrowser to a PHP-enabled webserver and dumped the images in appropriate directories (1 per album), and ran the thumbnailing script. It handles cropping of the images, and optimizing their size for you. So much better than using something like Menalto Gallery where you have to upload them through an awkward upload interface.
Try this out
http://www.lunarvis.com/products/tinymcefilebrowserwithupload.php
Depends on the web server. If you can use servlets, try this :
// UploadServlet.java : Proof of Concept - Mike Smith March 2006
// Accept a file from the client, assume it is an image, rescale it and save it to disk for later display
import javax.servlet.http.*;
import javax.imageio.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.servlet.*;
import java.awt.image.*;
import java.awt.*;
public class UploadServlet extends HttpServlet {
public static void printHeader(PrintWriter pw) {
pw.println("<HEAD><TITLE>Upload Servlet</TITLE><HEAD>");
pw.println("<BODY>");
}
public static void printTrailer(PrintWriter pw) {
pw.println("<img src=\"../images/poweredby.png\" align=left>");
pw.println("<img src=\"../images/tomcat-power.gif\" align=right>");
pw.println("</BODY></HTML>");
}
public void init() { // Servlet init() : called when the servlet is LOADED (not when invoked)
}
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException {
DiskFileItemFactory dfifact;
ServletFileUpload sfu;
java.util.List items;
Iterator it;
FileItem fi;
String field, filename, contype;
boolean inmem, ismulti;
long sz;
BufferedImage img;
int width, height, nwidth, nheight, pixels;
double scaling;
final int MAXPIXELS = 350 * 350;
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
printHeader(pw);
ismulti = FileUpload.isMultipartContent(req);
if (ismulti) {
pw.println("Great! Multipart detected");
dfifact = new DiskFileItemFactory(999999, new File("/tmp"));
sfu = new ServletFileUpload(dfifact);
try {
items = sfu.parseRequest(req);
} catch (FileUploadException e) {
pw.println("Failed to parse file, error [" + e + "]");
printTrailer(pw);
pw.close();
return;
}
it = items.iterator();
while (it.hasNext()) {
fi = (FileItem) it.next();
if (fi.isFormField()) {
pw.println("Form field [" + fi.getFieldName() + "] value [" + fi.getString() + "]");
}
else { // Its an upload
field = fi.getFieldName();
filename = fi.getName();
contype = fi.getContentType();
inmem = fi.isInMemory();
sz = fi.getSize();
pw.println("Upload field=" + field + " file=" + filename + " content=" + contype + " inmem=" + inmem
+ " size=" + sz);
InputStream istream = fi.getInputStream();
img = ImageIO.read(istream);
nwidth = width = img.getWidth();
nheight = height = img.getHeight();
pixels = width * height;
if (pixels > MAXPIXELS) {
scaling = Math.sqrt((double) MAXPIXELS / (double) pixels);
nheight = (int) ((double) height * scaling);
nwidth = (int) ((double) width * scaling);
}
BufferedImage output = new BufferedImage(nwidth, nheight, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g = output.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img, 0, 0, nwidth, nheight, null);
ImageIO.write(output, "jpeg", new File("/var/tomcat/webapps/pioneer/demo.jpg"));
istream.close();
}
}
}
else
pw.println("Bugger! Multipart not detected");
printTrailer(pw);
pw.close();
}
public void destroy() {
}
}
GIMP (http://www.gimp.org/) is a good tool for doing resize and is open source.