What I have
I have an image File object trying to post to Tumblr using Jumblr API
My problem
When I try to post the image I get com.tumblr.jumblr.exceptions.JumblrException: Bad Request Response code :400
My code
client = new JumblrClient(CONSUMER_KEY,SECRET_KEY);
client.setToken(TOKEN, TOKEN_SECRET);
User user=client.user();
userName=user.getName();
PhotoPost photoPost=client.newPost(client.user().getBlogs().get(0).getName(),PhotoPost.class);
photoPost.setCaption("My Tumblr post");
photoPost.setPhoto(new Photo(Methods.FILE_IMAGE));
photoPost.save();
I've encountered the same issue using Jumblr.
Instead of this method (does it somehow trigger Android gallery? Couldn't find any javadoc for Methods.FILE_IMAGE)
photoPost.setPhoto(new Photo(Methods.FILE_IMAGE));
I suggest you to try any flavor of
photoPost.setData(new File(fileName)); //if it's possible on Android
And please try it with different files: Tumblr has not only file-size limitations, but also some weird check for file being valid. ~3% of gif files I upload throw Bad Request Response code :400. Those files are not exceeding GIF size limit and they're displayed fine on my machine, but Tumblr, for some reason rejects them, so please try post.setData and try it with some bulletproof-valid file, because from the rest of your code - it definitely looks like you're doing it right
I had a similar problem posting a video & audio. However, posting an Image worked like a charm..
JumblrClient client = new JumblrClient(
CONSUMER_KEY,
SECRET_KEY
);
client.setToken(
TOKEN,
TOKEN_SECRET
);
PhotoPost post = client.newPost(strBlogName, PhotoPost.class);
post.setCaption("This is my caption");
post.setData(new File(fileUri.getPath()));
post.save(); //Initiates upload of image file
Related
i am trying to create an app which removes the image background, the send the image through api key and server sends the response, here i get response but i coulnt understand the response image format. PLEASE senior developer and programmers help me.
sample response code : : ‰PNG
������IHDR����˜����������,ƒ7ª����
{{{;Ž}ƒ#âtp¶8_<Nˆ+ÄUàZp'pWp¸¼ÞïŒÅóðËñeøF|?ŽŸ!(Œ ®„HBa-¡’ÐF8K¸KxA$õˆNÄp¢€¸†XI<D<O%¾%QHf$6)$!m!í'"Ý"½ “ÉFdr<YLÞBn&Ÿ!ß'¿Q X(ðV+Ô(t\Qx¦ˆW4TôT\¬˜¯X¡xDqHñ©^ÉH‰-ÄQZ¥T£tTé†Ò´2UÙF9T9Cy³r‹òåG,ňâCáQŠ(û(g(cT„ªOeS¹ÔuÔFêYê8C3¦ÐRi¥´ohƒ´)ŠŠJ´JžJÊq)¡Ñèéô2úaúuú;U-UOU¾ê&Õ6Õ+ª¯Õæ¨y¨ñÕJÔÚÕFÔÞ©3Ô}ÔÓÔ·©w©ßÓ#i˜i„käjìÑ8«ñtmŽË9‡çÜÖ„5Í4#4WhîÓÐœÖÒÖòÓÊÒªÒ:£õT›®í¡ª½Cû„ö¤UÇMG ³Cç¤Îc†
5eCÙ‹²»Å4ÙÏÔ€ÄD²^2šã–S“ó&7:÷Hžrž0o¹ÙòMË'ò}ó¿^ZÁ]Ñ[ [°¶t¥çÊúUЪ¥«zWë¯.Z=¾Æo͵„µik(´.,/|¹.f]O‘VÑš¢±õ~ë[‹ŠEÅ76¸l¨ÛˆÚ(Ø8¸iMKx%K-K+Jßoæn¾ø•ÍW•_}Ú’´e°Ì¡lÏVÌVáÖëÛÜ·(W.Ï/Û²½scGÉŽ—;—ì¼PaWQ·‹°K²KZ\Ù]ePµµê}uJõHWM{-fí¦Ú×»y»¯ìñØÓV§UWZ÷n¯ïÍz¿úΣ†Š}˜}9û6F7öÍúº¹I£©´éÃ~á~éˆ}ÍŽÍÍ-š-e¬p«¤uòÂÁËßxÓÝÆl«o§·—‡$‡›øíõÃA‡{°Ž´}gø]mµ£¤ê\Þ9Õ•Ò%íŽë>x´·Ç¥§ã{Ëï÷Ó=Vs\åx٠‰¢ŸN柜>•uêééäÓc½Kz=s-/¼oðlÐÙóç|Ïé÷ì?yÞõü±ÎŽ^d]ìºäp©sÀ~ ãû:;‡‡º/;]îž7|âŠû•ÓW½¯ž»píÒÈü‘áëQ×oÞH¸!½É»ùèVú¬ç·snÏÜYs}·äžÒ½Šûš÷~4ý±]ê =>ê=:ð`Áƒ;cܱ'?eÿô~¼è!ùaÅ„ÎDó#ÛGÇ&}'/?^øxüIÖ“™§Å?+ÿ\ûÌäÙw¿xü20;5þ\ôüÓ¯›_¨¿ØÿÒîeïtØôýW¯f^—¼Qsà-ëmÿ»˜w3¹ï±ï+?˜~èùôñOŸ~÷„óû¤Ì\9������ pHYs����������šœ������IDATx^ìýœ¤éUÞŸÊ
Well, this is PNG as it starts with ‰PNG..
I'm trying to do a post request with a WebView on Android.
After searching for days and trying dozens of things i couldn't get it work. In SWIFT it's just a few lines of code so i thought there must also be a simple way to do a post request for a webview on android.
As (for 2016) EncodingUtils and HTTPClient are deprecated this are my current approaches:
String url = "http://example.com/php.php";
String postData = null;
postData = "param1=" + URLEncoder.encode("1234567890", "UTF-8");
webcontent.postUrl(url,postData.getBytes());
//or
webcontent.postUrl(url, Base64.encode(postData.getBytes(), Base64.DEFAULT));
Both just result in a blank screen. There is just one parameter to be sent and a string containing html from the server should be received.
In addition, the php on the server returns a html-string with colored background irrespective of any input, but even this isn't displayed so maybe the whole request never reaches the server?
Thanks in advance!
In Android you do not use webView to access the content of the HTTP response. You'll need to use HttpClient for that purpose!
See this nice tutorial which explains the fundamentals! Also see this video if you find it hard!
Hope it helps!
Im struggling to find a solution or library with good documentation describing how to submit a multipart image to a server. I had a look at loopJ, which I think is very promising however I am still unsure what the best solution is. It would be great if someone could give me advice/strategy or code example I have used in my iOS, (AFNetworking) shown below:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = #{#"userID": #"1234567890"};
// add parameters first (user id) and then multipart image
[manager POST:MAIN_URL parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
// add multipart image
[formData appendPartWithFileData:imageData name:#"uploadFile" fileName:#"uploadFile" mimeType:#"image/jpg"];
} success:^(AFHTTPRequestOperation *operation,
id responseObject) {
NSLog(#"Success: %#", responseObject);
} failure:^(AFHTTPRequestOperation *operation,
NSError *error) {
NSLog(#"Error: %#", error);
}];
Where imageData is the Image that needs to be uploaded.
I used the Apache's Multipart Entity Builder. Then just convert your image into a byte array or input stream.
http://hc.apache.org/httpcomponents-client-ga/httpmime/apidocs/org/apache/http/entity/mime/MultipartEntityBuilder.html
http://loopj.com/android-async-http/ seems to be pretty easy to use for android networking including multipart (just like AFNetworking for IOS).
The only thing I'm still struggling with, how to update a view (progress bar) while it's uploading. I also need to upload bunch of files synchronously (one at a time) which also seems to be not as easy as I thought (as least I have not found a solution for it yet). If anyone has any hints on using loopj asynchronously -- would be much appreciated.
hello am trying to get images from an album from picasa in an android app. I tried creating an album and the album was created successfully however there is something wrong when i try to get the images in the album. Please find below my code:
PicasawebService myService = new PicasawebService("myApp");
myService.setUserCredentials("username", "password");
URL url = new URL ("https://picasaweb.google.com/data/feed/api/user/myusername/albumid/myalbumid");
AlbumFeed feed= myService.getFeed(url, AlbumFeed.class);
List<MediaContent> l;
for(PhotoEntry photo : feed.getPhotoEntries()){
l= photo.getMediaContents();
return l.get(0).getUrl().toString();
}
the for loop is not being entered but when i check the size of the feed and it shows me the correct number of images in the album. I got the code from google developers guide:(https://developers.google.com/picasa-web/docs/2.0/developers_guide_java#listalbums)
NB: i tried the same exact code in a desktop app and worked perfectly.
Thank you
EDIT: The problem is that the ALbumFeed is returning entries of class GPhotoEntry and not PhotoEntry. I searched online and the solution was to include the gdata-photos-meta.jar in my library which was already included...Any idea?
google's GData doesnt work with android. You should use google Client api and they say that there is a running sample for picasa on android.
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.