I am trying to get the image URL from the Dropbox and I followed the below code from the documentation.
try {
Entry directory = dropboxApi.metadata("/", 1000, null, true, null);
directory.mimeType = "image*//*";
for (Entry entry : directory.contents) {
DropboxAPI.DropboxLink link = dropboxApi.media(entry.path, false);
if (link.url.contains(".jpeg") || link.url.contains(".png") || link.url.contains(".jpg"))
files.add(link.url);
}
} catch (DropboxException e) {
e.printStackTrace();
}
Based on this code I can get the image URL. But it is not working after hours.
In my scenario, I want to get the image URL and I will send it to server API. So when I retrieve other API, I will get the image URL, what I sent. Once I got the URL, just I want to set it to imageview.
I have verified this link. I got the different link by using share method. But I don't know how to set that into my ImageView, whereas by using media method I can get the URL and I can set it to ImageView.
Please can someone help me to solve this problem
If i make an Http request for share url then I am getting image name with download option.
I am getting 16 headers.
From this am not getting any clue. There is no header name contains Location.There is one content-piracy-policy which gives some url values combined. But it is also not relevant.
Related
I have a problem when wanna get my photos from dropbox and load it into GridView and i want use Picasso in adapter too.
method load() will take a downloadable URL ,
PS: i'm using Dropbox Android SDK 1.6.1
if i used method media() and fetch url from dropbox like that :
// Get the metadata for a directory , | request |
DropboxAPI.Entry dirent = Log_in.mApi.metadata(Log_in.APP_DIR + "/images/", 1000, null, true, null);
if (!dirent.isDir || dirent.contents == null) {
// It's not a directory, or there's nothing in it
mErrorMsg = "File or empty directory";
//return false;
}
// Make a list of everything in it that we can get a thumbnail for
thumbs = new ArrayList<>();
imagePath = new ArrayList<>();
for (DropboxAPI.Entry ent : dirent.contents) {
if (ent.thumbExists) {
// Add it to the list of thumbs we can choose from
thumbs.add(ent);
// do another requests (many requests to dropbox to get the urls , and this is terrible it takes request time for each image !
imagePath.add(Log_in.mApi.media(ent.path,true).url);
}
}
it is not practicle at all cuz it would take so much time to get every url this is the scenario :
Search images in Photos folder (1 request)
Using [media][1] for getting direct URL (1 * (images) requests)
Using Picasso in adapter (1 * (images) requests)
I will have count(images) * 2 + 1 requests count
it is terrible , need a better solution .
PS : i tried this https://medium.com/#jpardogo/requesthandler-api-for-picasso-library-c3ee7c4bec25#.wpmea1eci
but the code is not complete there is some classes not resolved/exist and some variables not defined .
so any one got an idea on how to work with dropbox images api using picasso .
i think there is a sample from dropbox about this, try to check this link dropbox sample
there is 2 files that you need to see PicassoClient.java And FileThumbnailRequestHandler.java
I want to send a image taken by the user to a Facebook share dialog post.
The image taken from device camera h is set to a imageview and also saved to the device external storage/ SD card.
The facebook share SDK takes a URL for a image in the .setPicture(URL) method.
So my question is it possible to get the URL of a image from either the bitmap in the imageview or the image stored in the deice?
Or is the URL specifically for a network resource?
Cheers
ciaran
EDIT: Have tried adding the path to sd card/external storage of device as a string to the
setLink(URL string) method:
setLink("/storage/emulated/0/dive_photos/image2462.png")
but image does not load, exceptions thrown in Logcat is ....
03-02 00:06:04.280: E/Activity(3055): Error:
com.facebook.FacebookException: Error publishing message Share preview
could not be fetched
(#100)picture url not properly formed
Treied removing the first "/" by getting substring(1) and passing setLink("storage/emulated/0/dive_photos/image2462.png")
but same error....
Although a network resource url works fine:
setLink("http://www.mooneycallans.com/images/Gallery/image51.jpg")
EDIT:
Also tried creating a file://imagePathString URL some progress made, the share preview will show the image however will still not post get the same (#100) Pictire URL not properly formed....
File imagePathFile = new File(savedImagePath);
try{
userImageURL = imagePathFile.toURI().toURL();
Log.d(TAG, "File URL for saved image on FB: " + userImageURL);
}catch(MalformedURLException ex){
//ex.printStackTrace();
}
userImageURLString = userImageURL.toString();
setPicture(userImageURLString)
//userImageURLString = "file:/storage/emulated/0/dive_photos/image4373.png";
My head is wrecked:(
After much seraching a very confusing FB documentation I found the method
setPicture(URL string)
will only accept a network resource URL.
To upload a photo form app need the Request class:
Request.newUploadPhotoRequest(session, imagePathFile, uploadPhotoRequestCallback);
I used graph API Json Response of Facebook Wall Post Images and display in my APP i successfully got it. But the wall images look very Blur how to resolve? i used this code for get wall picture
URL url=new URL(hashMap.get("picture_url"));
bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream());
((ImageView)view.findViewById(R.id.imageView_FullImage)).setImageBitmap(bitmap)
The Facebook Graph API as well as the FQL data set always returns the Picture URL of a thumbnail. If you look at the URL it returns, it will have one of these ending (right before the image extension .jpg, .png, etc) _t., _a.. For example, if the URL is to a JPG file, it could have an ending _t.jpg
The idea is to swap the ending and choose a normal size for the image that is returned. To do this, use the code below that will replace the endings with the one for normal sized images (that should have the _n.)
By the way, I don't think the tag you are looking for is picture_url. It should be just picture. But regardless, get the source URL as shown below, replace the endings and then pass it to the this line in your code:
// THIS SHOULD BE AFTER THE if....else code block
bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream());
CODE TO REPLACE THE VARIOUS THUMBNAIL IMAGES: By the way, this is production code and works perfect.
String PICTURE_URL;
String getPicture = JOFeeds.getString("picture");
if (getPicture.contains("_t.")) {
PICTURE_URL = getPicture.replaceAll("_t.", "_n.");
} else if (getPicture.contains("_a.")) {
PICTURE_URL = getPicture.replaceAll("_a.", "_n.");
} else if (getPicture.contains("_s.")) {
PICTURE_URL = getPicture.replaceAll("_s.", "_n.");
} else if (getPicture.contains("_q.")) {
PICTURE_URL = getPicture.replaceAll("_q.", "_n.");
}
Note: However, in some cases, like a Video preview or a Link preview, it will not always have a bigger image available. Nothing much you can do about it nor can Facebook I suspect. These typically come from posts that are shared by users from other websites.
I had successfully integrate twitter API and I am able to post text from my device but I want to know two things
Is is possible to post Image on twitter using API in Android ?
In twitter we used OAuth.OAUTH_TOKEN and OAuth.OAUTH_TOKEN_SECRET tokens.I passing token values on second argument in below code is it ok ? or I have to leave it blank ?
String token = prefs.getString(OAuth.OAUTH_TOKEN, OAuth_token_key);
String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, OAuth_token_secret);
I searched to know whether is it possible to post image on twitter using twitter API in Android but I have not found any link that I know whether it is possible or not.
I got one similar post image issue for iPhone and there is a answer also. I don't know about iPhone so I can't know weather it is right answer or not.Here is a link of similar question of post image for iPhone
Please help me out from this issue.
Yes You can post the Image on the Twitter.
AIK, there are two methods to upload the photo to the Twitter.
With First you have to implemente the Twitter API and use this Link to upload the Photot to the Twitter.
Sorry for the Example. as i dont get any example for how to use this.
With Second you can do this with the help of the twitPic4j API.
Just add the API for twitPic4j and write below code to upload the photo.
Code:
File picture = new File(APP_FILE_PATH + "/"+filename+".jpg");
// Create TwitPic object and allocate TwitPicResponse object
TwitPic tpRequest = new TwitPic(TWITTER_NAME, TWITTER_PASSWORD);
TwitPicResponse tpResponse = null;
// Make request and handle exceptions
try {
tpResponse = tpRequest.uploadAndPost(picture, customMessageEditText.getText()+" http://www.twsbi.com/");
}
catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Please enter valid username and password.", Toast.LENGTH_SHORT).show();
}
catch (TwitPicException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Invalid username and password.", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "Please enter valid Username and Password.", Toast.LENGTH_SHORT).show();
}
// If we got a response back, print out response variables
if(tpResponse != null) {
tpResponse.dumpVars();
System.out.println(tpResponse.getStatus());
if(tpResponse.getStatus().equals("ok")){
Toast.makeText(getApplicationContext(), "Photo posted on Twitter.",Toast.LENGTH_SHORT).show();
//picture.delete();
}
}
Above code works in for my case.
Hope you got the sollution with the second one and i dont know how to use the first one.
Enjoy. :)
Updated
If still it not works for you and try some project listed below:
Example 1
Example 2
Example 3
Example 4
Hope that will help you.
Happy Coding.
==================================
FOR erdomester and Updated answer
==================================
Please check my first link given with Example1 and its api: Twitter4J
So, if any library that stop giving functionality to upload image on twitter, you can use other library for same. Please check and read regrading Twitter4j.
Check Twitter4J API to upload file to Twitter: Twitter4j Image Upload
For instance help you can also check below code to upload image file on Twitter.
Code to upload Image:
/**
* To upload a picture with some piece of text.
*
*
* #param file The file which we want to share with our tweet
* #param message Message to display with picture
* #param twitter Instance of authorized Twitter class
* #throws Exception exception if any
*/
public void uploadPic(File file, String message,Twitter twitter) throws Exception {
try{
StatusUpdate status = new StatusUpdate(message);
status.setMedia(file);
twitter.updateStatus(status);}
catch(TwitterException e){
Log.d("TAG", "Pic Upload error" + e.getErrorMessage());
throw e;
}
}
I hope this will help you more for your query.
Thanks to eredomester to notify me that tweetpic is no more working for Twitter. But please dont do downvote to answer untill you have not fully search on the given reply. Given library Twitter4J in Example1 gives clear idea about uploading image to twitter and you can easily implement it.
For more help and code you can also check: Twitter Upload media
Note: To use this please make sure you have latest jar file. I have used twitter4j-core-2.2.5.jar or more for this.
Please comment me instead of downvoting this answer, if you facing any issue in this.
Is is possible to post Image on twitter using API in Android ?
Yes you can upload Images to Twitter after successful Authentication Using Twitter Media Uplload.
In twitter we used OAuth.OAUTH_TOKEN and OAuth.OAUTH_TOKEN_SECRET
tokens.I passing token values on second argument in below code is it
ok ? or I have to leave it blank ?
You should add both Token and Token Secret Key it will be useful for setTokenWithSecret methos of Tiwtter in which you have to send both Token and Token Secret..
Yes you can post image on twitter using Twitter api like twitter4j but I will suggest you to do using HttpPost class and DefaultHttpClient class because its good in practice and you dont need to add any external twitter api to it.
I am developing an application for Android and which uses Dropbox for organizing the files. I am exploring the Dropbox API but its description and help is limited, as there is no documentation for the Dropbox API.
I still would like to manage the files to some functionality, for example placing a file and getting a file from Dropbox. Now the problem is when I put some files in Dropbox public folder and I need a URL to share to my contacts in the application. But in the API I could not find any function that returns the web URL of the file to share (Just like in the Deskotop interface of Dropbox, a user can get a Shared URL to send to friends).
Could someone help me figure out how to share that file with contacts in the Application?
Or any other way to share a file using Dropbox Android API?
According to changes made on DropBox metioned here: https://www.dropbox.com/help/16/en
There would be no more Public folders, instead access to files can be done via Share Link.
If you use Android DropBox Core Api then shared link can be retrieved this way:
// Get the metadata for a directory
Entry dirent = mApi.metadata(mPath, 1000, null, true, null);
for (Entry ent : dirent.contents) {
String shareAddress = null;
if (!ent.isDir) {
DropboxLink shareLink = mApi.share(ent.path);
shareAddress = getShareURL(shareLink.url).replaceFirst("https://www", "https://dl");
Log.d(TAG, "dropbox share link " + shareAddress);
}
}
UPDATE: 2014/07/20 by Dheeraj Bhaskar
Use the following helper function alongwith the above function.
Since DropBox started to send shortened links it is little bit more problematic to get proper link.
For now, I am using this method :
We simply load the URL, follow the redirects and get the new URL.
String getShareURL(String strURL) {
URLConnection conn = null;
String redirectedUrl = null;
try {
URL inputURL = new URL(strURL);
conn = inputURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
System.out.println("Redirected URL: " + conn.getURL());
redirectedUrl = conn.getURL().toString();
is.close();
} catch (MalformedURLException e) {
Log.d(TAG, "Please input a valid URL");
} catch (IOException ioe) {
Log.d(TAG, "Can not connect to the URL");
}
return redirectedUrl;
}
Note: All of this should be done of course in AsyncTask or Thread. This will produce proper links ready to download
Update 2014/07/25: Change in dropbox share URLs
A heads-up on the kind of URLs to expect
From the Dropbox team:
We wanted to give you a heads up about an upcoming change to the URL
structure of Dropbox shared links. While not part of the API, the
change could affect apps that manipulate the URLs returned from the
/shares endpoint or the "preview" link type returned by the Chooser
Drop-in.
Links returned will now have a ?dl=0 appended to them.
E.g., instead of
https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx, you'll
receive URLs
like this link
https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx?dl=0.
A useful thread in the Dropbox forums:
http://forums.dropbox.com/topic.php?id=37700&replies=7#post-326432
IF The public link for a file is always
dl.dropbox.com/u/<your users uid>/<path under /Public>/filename
then we can just use the API to get and build the public URL in the code.
Perhaps this may also help: Upload a file to Dropbox and copy public address. This script upload a file to your /Public directory and use your accound
UID to build it's public URL. Then, it echoes the URL to the console.
https://github.com/sylvainfilteau/dropbox-api-command/commit/6aa817c79220c5de4ff5339cd01ea8b528bcac36
I am not there yet in my Dropbox interface implementation, but this is one of the functions I need to develop. More in one or two days I hope.
I believe the url is as follows:
http://dl.dropbox.com/u/YOUR_DROPBOX_ID/YOUR_FILE_NAME