I want to share multiple images along with the tweet on the Twitter, but i am not able to do so. I am able to tweet single photo along with the message but not getting to append other photos in the same tweet since twitter does not allow to tweet the same message for 8-10 hours or even a day. Here is my code, what i have done to tweet the message along the photo. Can anyone please let me know where i am lacking in the code or any better way to implement the requirement.
Here is the code for tweeting:
AccessToken accessToken = new AccessToken(access_token,
access_token_secret);
Twitter twitter = new TwitterFactory(builder.build())
.getInstance(accessToken);
File f = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath().toString()
+ "/xyz.png");
StatusUpdate statusUpdate = new StatusUpdate(status);
statusUpdate.setMedia(f);
twitter.updateStatus(statusUpdate);
Thanks in advance
After doing lot of R & D, i came to know that we can not post more than one image in a single tweet, and also Twitter does not allow same message to be twitted in short span of time. You can post it after several hours(may be around 7-8 hours), since it gives "Duplicate message error". So i called the function which helped posting tweet with the media file by taking one counter variable and checking with the list of images i had. So at the end i was able to post three different tweets as there were three images in my list.
And ya, you can check in this link in which you will come to know the number of images you can post in a single tweet
Related
I want to post a tweet with image and text in my android app,but i want to # some other people at the same time,how should I do?
the twett result that I get just like ,that is from my publish # my friend.
my code:
StatusUpdate statu = new StatusUpdate("tweet text");
File tweetImg = getTwitterImagFile();
statu.setMedia(tweetImg);
mTwitter.updateStatus(statu);
You just need to add #[user_handle] to tweet text. If you are replying a tweet, you can set the parameter in_reply_to_status_id in the POST request.
See: https://dev.twitter.com/rest/reference/post/statuses/update
I want to post a pre-defined message on Facebook through my android application. I got everything to work except the 'properties' field. I want to post a message where it says:
More information: here
and when the user clicks on 'here', it should link to the page.
This is what I did:
Bundle params = new Bundle();
String s2 = "{'More information':{'text':'here', 'href':" + details + "}}";
params.putString("properties", s2);
where 'details' is the link to the page.
But it seems like facebook is not picking up this line. I successfully set up the caption, picture and other fields.
Any insights? Thanks!
This is by design, as far as I know, we do not support HTML in status updates. We will automatically create a link if you post a valid URL however, so I would suggest just pasting out the full link
".....More information: (www.yourURLhere.com)"
On Facebook, www.yourURLhere.com will be a clickable link.
I am posting to a user's wall on Facebook. How can I add a link to the post next to the like and comment links, as seen on the illustration below. What is the parameter name I should include in my request?
This is what I eventually did:
The link besides the like and comment is called "actions". To add it, you need to create an array of actions (actually, as I understand only one action is supported). For example:
JSONObject actions = new JSONObject();
actions.put("name","Get Your App");
actions.put("link", "Your app URL");
parameters.putString("actions", actions.toString());
Here is list of all Post Fields.
link | The link attached to this post | Requires access_token | string containing the URL
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.
This code WAS working fine, but suddenly stopped showing the map thumbnail from either Bing or Google static maps.. Any ideas? Did Facebook change their own parsing of the picture urls?
Bundle parameters = new Bundle();
parameters.putString("message", et_message.getText().toString());
parameters.putString("description", "Currently Near");
parameters.putString("picture","http://maps.google.com/maps/api/staticmap?center=36.837812,-76.022045&zoom=15&size=110x110&sensor=false&maptype=hybrid&markers=color:blue|36.837812,-76.022045");
parameters.putString("caption", lStreet + " - " + lCity +", "+ lState + " : "+ lPhone);
parameters.putString("name", lName);
if(lUrl != null){parameters.putString("link", lUrl);}
mAsyncRunner.request("me/feed", parameters,"POST", new myPostListener(), 1);
Now the Wall Post on my Facebook seems to be changing the link to combine parts of the LINK url, along with the image URL. I don't have a clear example of this that I can post, but a rough example is:
link = http://foo.bar/
picture = http://somemaps/image1.jpg
Result when hovering over the broken image on Facebook is something like:
http://apk.facebook/http://somemaps/image1.jpg
I don't get why Facebook isn't just using my raw picture Url in the first place!? Grrrrr
Anyone else having problem posting images to facebook wall, where image is a realtime generated image from Bing Maps, or Google Static Maps API?
I was having a similar issue and after a long debugging session it was due to me not providing a link and name attribute along with the picture attribute. I was just sending in message and picture but I think Facebook changed the way you can post pictures in a post recently because this did work about a month ago when I was testing.... Make sure they are all included in your post to Facebook. To post a picture you have to post to /me/photos, can't just send in a link unless you want it displayed as a "Facebook Link". Hope that helps.