Not able to Get twitter Profile pic of users api 1.1 - android

I want to get Profile picture from twitter api.
i have tried the following methods .
a) as per this url :Twitter4j authentication credentials are missing and Retrieve the user profile image from twitter
//Twitter Conf.
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_SECRET)
.setOAuthAccessToken(ACCESS_KEY)
.setOAuthAccessTokenSecret(ACCESS_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
User user = twitter.showUser(id of other user who using same app);
user.getOriginalProfileImageURL()
in this method get Exception
08-29 09:05:26.282: W/System.err(3823): 404:The URI requested is invalid or the resource requested, such as a user, does not exists. Also returned when the requested format is not supported by the requested method.
08-29 09:05:26.282: W/System.err(3823): message - Sorry, that page does not exist.
b) as per this latest url
https://dev.twitter.com/docs/api/1.1/get/users/profile_banner
pass screen name of user here :
https://api.twitter.com/1.1/users/profile_banner.json?screen_name=iRohitSachdeva
response: {"errors":[{"message":"Bad Authentication data","code":215}]}.

The correct thing to do is work out why your authentication data is going wrong.
However, the simple way to get profile images is using a service like http://avatars.io/
For example, the get my avatar, visit http://avatars.io/twitter/edent
It should return the correct URL for my Twitter account's pic.

Related

Redirect url for Google OAuth Android

Never really worked with OAuth, trying to implement it now, I want to get access token and profile data from google and facebook. Using Xamarin.Auth.
With Facebook there're no problems, I specify "http://www.facebook.com/connect/login_success.html" as redirect url and after I login it goes back to the activity I was before.
However with Google it's not as smooth - couldn't find any similar to facebook login success pages, somewhere found suggestion to use "https://www.googleapis.com/plus/v1/people/me" - added it to redirect url white list, however after sign in I would get "Redirect_url_mismatch" A native application: application nameaccording to their documentation I should use "my.package.name:" and again I added that to redirect url white list, attempted to sign in, this time after sign in screen I get to second screen where I need to confirm read permissions and after that I get very short error something like "com.my.package:/?oauthparameterX=value1...." and get redirected to permission screen again.
Here's my complete OAuth2Authenticator:
var auth = new OAuth2Authenticator(
clientId: SocialIds.GooglePlusId,
clientSecret: SocialIds.GooglePlusSecret,
scope: OAuthUrl.GoogleScope,
authorizeUrl: new Uri(OAuthUrl.GoogleAuthorize),
redirectUrl: new Uri("https://www.googleapis.com/plus/v1/people/me"),
accessTokenUrl: new Uri("https://accounts.google.com/o/oauth2/token"),
getUsernameAsync: null);
auth.AllowCancel = false;
urls:
public static string GoogleAuthorize = "https://accounts.google.com/o/oauth2/auth";
public static string GoogleScope = "https://www.googleapis.com/auth/userinfo.email";
public static string GoogleRedirect = "https://www.googleapis.com/plus/v1/people/me";
public static string GoogleUserInfo = "https://www.googleapis.com/oauth2/v1/userinfo?access_token={0}";
In the above listed code, you are not giving the redirect uri instead you are giving the scope of google api. The purpose of redirect uri is to recieve the response from google api after authorization. The response should be a code. This response code is used for accessing the access_token,refresh_token, id_token etc. So you have to recieve this code in your project side.For this purpose , the redirect uri is used.
Go to your google console, create project, add credentials, then you will be redirect to a page conatains,
You can find the authorized redirect url. Give the url , then configure your code with new redirect url . Everything will be fine after this.

How to display logged in user's profile picture in android app using ProfilePictureView from Facebook SDK?

I want to display the profile picture of a logged in user in my android app.How to do that using the method ProfilePictureView in Facebook SDK?Please help...
If you want to display the user's photo using the CircularImageView library. You can still make requests to the Facebook Graph API and parse the response by yourself. You can do this manually or using the Android SDK for Facebook by making a request to the following endpoint...
graph.facebook.com/v2.1/me/picture
of course, you can replace me by a specific user's id. You don't need to request any special permissions in the access token. The request about will render a json response similar to the one below...
{
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/v/t1.0-1/blahblahblah_n.jpg?oh=2xgdgfdhgdhdhg33ba58e021&oe=5dghgdh_gda__=1dgfhdfh88_b9gdhfghfghfghfghfgh408d6e7",
"is_silhouette": false
}
}
this json response contains the following fields:
url: which is a url from where you can request the profile picture
is_silhouette: which determines whether the picture is the default facebook silhouette or not. If the user has not added a profile picture, then the facebook default silhouette will be returned in the url...see below
You can also use the Android SDK for Facebook, create a request object, pass in the current session object, execute the request asynchronously, for example...
new Request(
_currentSession,
"/me/picture",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
//parse the response
}
}
).executeAsync();
For more information you can read the documentation on their site and even use the Graph API Explorer for testing purposes

Authentication credentials missing error when trying to get a twitter timeline using twitter4j

I am trying to retrieve the tweets from a twitter users timeline using the Twitter4j library and integrate them into an android app. I have gone through all the specific steps to get my consumer keys/access tokens and have then set them in my code in the following way.
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_SECRET)
.setOAuthAccessToken(ACCESS_TOKEN)
.setOAuthAccessTokenSecret(ACCESS_SECRET)
.setApplicationOnlyAuthEnabled(true);
Configuration config = cb.build();
tf = new TwitterFactory(config);
twitter = tf.getInstance();
bearerToken = twitter.getOAuth2Token();
twitter.setOAuth2Token(bearerToken);;
// The factory instance is re-useable and thread safe.
twitter = tf.getSingleton();
statuses = twitter.getUserTimeline(name);
However when I run the application, I get the following error:
Caused by: java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/en/configuration.html for details
at twitter4j.TwitterBaseImpl.ensureAuthorizationEnabled(TwitterBaseImpl.java:186)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1554)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:129)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:150)
Note: I have searched through numerous similar questions on here on this topic and have had no success thus far.
Any help would be greatly appreciated guys!

Using username in facebook graph api post

I am posting to user's wall using following code using restFB.
String myAccessToken = null;
String appId="my app id ......";
String appSecret="my app secret";
// facebook user id of the user on whose wall to post
String userId="user id ...";
DefaultFacebookClient dfc = new DefaultFacebookClient();
AccessToken accessToken = dfc.obtainAppAccessToken(appId,appSecret);
myAccessToken = accessToken.getAccessToken();
FacebookClient facebookClient = new DefaultFacebookClient(myAccessToken);
FacebookType publishMessageResponse = facebookClient.publish(userId+"/feed", FacebookType.class, Parameter.with("message", "test"));
System.out.println("Published message ID: " + publishMessageResponse.getId());
All is working fine.
But now I want to include user's facebook first name in the post. Is there any way to do so? I dont want to generate yet another request to facebook for getting the username, as I am already generating 2 requests for getting user id(from redirect url). Is there any mechanism that graph api itself replaces some kind of tag in the post text with user name.
E.g I send the following text to post on user wall:
#username# is doing something...
And it is replaced by facebook graph api
Mark is doing something....
I dont want to generate yet another request to facebook for getting the username, as I am already generating 2 requests for getting user id(from redirect url).
No you can't. You have to make the request to fetch the name. /me?fields=name
But why does it matter, it'll take very less time to query this.

Can we post image on twitter using twitter API in 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.

Categories

Resources