sharing a photo to twitter from an android app - android

in my app i am showing some photos which are uploaded to our local server. If the user likes the photos he can share it to twitter and thru email.
Is there any way to share a image to email when it is been stored in an url.
Following is my twitter code
Intent i = new Intent(getApplicationContext(), PrepareRequestTokenActivity.class);
i.putExtra("imagetitle", imgtit);
i.putExtra("image_path", get_intent_path );
startActivity(i);
how could it be shared to a twitter wall

You can use twitter4j and can share photo and text. A sample code is given bellow.
public void Share_Pic_Text_Titter(File image_path, String message,
Twitter twitter) throws Exception {
try {
StatusUpdate st = new StatusUpdate(message);
st.setMedia(image_path);
twitter.updateStatus(st);
} catch (TwitterException e) {
Log.d("Error==>", "Pic Upload error" + e.getErrorMessage());
throw e;
}
}

Related

Open Facebook Profile in Android SDK

Note: This issue only arises when the Facebook app is installed.
I'm trying to open a user's Facebook profile page when an ImageButton is clicked. After looking at this suggested method for more recent Facebook app versions, it's mostly working, with the exception of users that are friends with the logged in user (in the app), or the logged in user themselves.
The process is:
Image button is clicked
Call to Facebook Graph API is made to get the link to the user's profile via their Facebook ID (stored in our database)
A new Intent is created by checking to see if the Facebook app is installed, and generating the correct Uri
A new Activity is started with the generated Intent
Because we're using Facebook Graph API v2.0, the username field is removed from the GraphUser object in the JSON. The problem is that the Facebook link (GraphUser.getLink()) is either:
An app-scoped (protected) link if the user (logged into the app) is not friends with the user whose profile we are trying to view; format is : https://www.facebook.com/app_scoped_user_id/{protected-id}
A 'normal' Facebook link with the user's real id (unprotected); format is: http://www.facebook.com/{real-user-id}
The real problem is that the Facebook Uri when the app is installed expects either:
An app-scoped link
A link with the username attached to it, not {user-id}
However, the web version (opened in a web view) doesn't care. The link can be app-scoped, username-based or id-based. So everything works for WebViews.
Since username is completely inaccessible in Graph API v2.0, I'm just getting null values, which means that for the Facebook app I can't generate the correct Uri that it expects (username-based), only id-based or app-scoped.
Here is the code that I'm using to create the Intent:
public static Intent getFacebookIntent(String facebookProfileUrl) {
PackageManager pm = App.getContext().getPackageManager();
Uri uri;
try {
pm.getPackageInfo("com.facebook.katana", 0);
uri = Uri.parse("fb://facewebmodal/f?href=" + facebookProfileUrl);
} catch (PackageManager.NameNotFoundException e) {
uri = Uri.parse(facebookProfileUrl);
}
return new Intent(Intent.ACTION_VIEW, uri);
}
And here is my onClick() method on the ImageButton:
new Request(
Session.getActiveSession(),
String.valueOf(mate.getFacebookId()),
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
GraphUser g = response.getGraphObjectAs(GraphUser.class);
String fbUrl = g.getLink();
// TODO: If link does not contain 'scoped', need USERNAME, not ID
String otherUrl = "https://www.facebook.com/" + myAppUser.getId();
String finalUrl = (fbUrl.contains("scoped")) ? fbUrl : otherUrl;
Intent intent = getFacebookIntent(finalUrl);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
).executeAsync();
I need the username if the app is installed, otherwise the web view deals with it as it should.
So the question: How can I get a Facebook username by id for the Facebook app? Or, is there a different Uri that the Facebook app expects that I can account for, using ids and not usernames?
You should be able to use the fb://profile/{user-id} URL format to launch native apps. This will let you use the user ID instead of a username. You could rewrite your getFacebookIntent method as:
public Intent getFacebookIntent(GraphUser user) {
PackageManager pm = this.getPackageManager();
Uri uri;
try {
pm.getPackageInfo("com.facebook.katana", 0);
uri = Uri.parse("fb://profile/" + user.getId());
} catch (PackageManager.NameNotFoundException e) {
uri = Uri.parse(user.getLink());
}
return new Intent(Intent.ACTION_VIEW, uri);
}
You could then call this method and pass in the GraphUser object.

Upload audio url in twitter android

i am stuck in Twitter integration.I am done with image uploading through url but i am not able to upload audio or video url to twitter.
Any help is appreciated. Thanx guys
Twitter Code for uploading youtube url:
twitter.updateStatus("This is My Youtube url Test http://youtu.be/pfHxl46KyZM");
Logcat:
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Error creating status.
code - 189
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=12c480e1
TwitterException{exceptionCode=[b2b52c28-12c480e1], statusCode=403, message=Error creating status., code=189, retryAfter=-1, rateLimitStatus=null, version=3.0.6-SNAPSHOT}
String tweetUrl = "https://twitter.com/intent/tweet?text=Put your Audio URL here &url="
+ "https://www.google.com&hashtags=android,twitter";
Uri uri = Uri.parse(tweetUrl);
startActivity(new Intent(Intent.ACTION_VIEW, uri));
OR
// Consumer
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
// Access Token
AccessToken accessToken = null;
accessToken = new AccessToken(ACCESS_TOKEN, ACCESS_SECRET);
twitter.setOAuthAccessToken(accessToken);
// Posting Status
Status status = null;
try {
status = twitter.updateStatus("YOUR_AUDIO_LINK");
} catch (TwitterException e) {
e.printStackTrace();
}
System.out.println("Successfully updated the URL: "
+ status.getText());
You cannot upload video directly to Twitter - they simply don't support it.
Follow these steps.
1.Upload the video to a 3rd party service (like YouTube)
2.Get the public URL of the uploaded video
3.Add the URL to the status you send to Twitter - e.g. "Look at my Birtday video http://youtube.com/id"
If you want, you can add a thumbnail of the video as an image attachment
Hope this is what you are looking for.
Note sure but check if this helps you:-
String videoPath="video file path";
TwitterSession twitterSession = new TwitterSession(MainActivity.this);
AccessToken accessToken = twitterSession.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(accessToken.getToken())
.setOAuthTokenSecret(accessToken.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(MainActivity.this, "Posted on Twitter and Twitvid" ,Toast.LENGTH_LONG).show();
Log.d("MainActivity", "Posted on Twitter and Twitvid");
} else {
Toast.makeText(MainActivity.this, "Post failed", Toast.LENGTH_LONG)
.show();
Log.d("MainActivity", "Posted failed");
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (ApiException e1) {
e1.printStackTrace();
}

Posting data from android app on my Twitter's account as tweet

I'm trying to post my data through android app on my twitter account so how should i do it.
i have tried a way, below is the code, and in that it is showing the data on my account and i need to click on the tweet button to get it tweeted. So can i know how to post it directly without asking me to tweet. Like Four Square app
public void open(View view){
String text = "Share Your Experiance ....!!!";
String url = "twitter://post?message=";
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url + Uri.encode(text)));
startActivity(i);
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(this, "Can't send tweet! Please install twitter...", 2).show();
}
Thanks in Advance !!!
Firstly you have to check are you logged with twitter or not after as your condition you can apply this snippet code.
I think you follow the all basics for twitter integration in your code.
public void uploadPic(String message, String getImgUrl)
throws Exception {
try {
System.out.println(" ON UPLOAD PIC FUNCTION getImgUrl "+getImgUrl);
// URL url = new URL("http://faveplatewebservice.siplstudio.com/uploads/big_dish/oooo14n7464rO4_thumb.png");
URL url = new URL(getImgUrl);
URLConnection urlConnection = url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
StatusUpdate status = new StatusUpdate("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message);
//status.setMedia(file);
status.setMedia("Check Out FavPlates on appstore, which offers you to add and find exciting dishes near you. "+message, in);
mTwitter.updateStatus(status);
} catch (TwitterException e) {
Log.d("TAG", "Pic Upload error" + e.getExceptionCode());
throw e;
}
}
hope it will help you!!
If you stuck anywhere then inform me.
Thankss!!

How can I get twitter user profile in android?

How can I get the user name, email, location, avatar, etc., of an authenticated user of Twitter in Android via the API?
I wrote the code below, but it always returns null at twitter.showUser(twitter.getId());
public User getUserInfo(Object accessToken)
{
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setOAuthConsumerKey(mConsumer.getConsumerKey());
configurationBuilder.setOAuthConsumerSecret(mConsumer.getConsumerSecret());
twitter4j.Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance();
try
{
twitter.setOAuthAccessToken((AccessToken) accessToken);
return twitter.showUser(twitter.getId());
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
I found another question here. People said that unable to retrieve email address of authenticated user of Twitter via api. So, How about other information such as fullname, avatar, phone number (if have),...?

EasyFacebook Android SDK - how do I get user photo?

I followed this tutorial http://kodefun.junian.net/2011/10/easy-facebook-android-sdk-simple.html and managed to successfully connect to facebook.
But how do I get user photos? Here's the code so far:
...
public void loginSuccess(Facebook facebook) {
GraphApi graphApi = new GraphApi(facebook);
User user = new User();
try{
user = graphApi.getMyAccountInfo();
//update your status if logged in
graphApi.setStatus("Hello, world!");
} catch(EasyFacebookError e){
Log.d("TAG: ", e.toString());
}
fbLoginManager.displayToast("Hey, " + user.getFirst_name() + "! Login success!");
List<Photo> listPh = graphApi.getAllPhotosMy();
Photo ph = listPh.get(0);
/// ... how do I get a user photo to drawable or something?
}
...
Any ideas? :) Thanks!
Just from messing around in there reference, I would say you would get the persons's ID and the feed that into a from, and then feed that from into the photo again.
I'm no expert on this, but there documentation is your friend.
http://www.easyfacebookandroidsdk.com/doc/index.html

Categories

Resources