I am working on Xamarin Android Application.I am using FacebooSdk for facebook-login.My problem is I am not getting email_Id and BirthDate of User.
This is how I give the permission:
LoginManager.Instance.LogInWithReadPermissions(this,new List<string>{"public_profile","user_friends","email","user_birthday"});
This is how I fetch the email Id and BirthDate:
emailId = e.mProfile.GetType ().GetProperty ("email").ToString ();
BirthDate = e.mProfile.GetType ().GetProperty ("user_birthday").ToString ();
If you are using xamarin's official facebook sdk. You can do this:
When creating loginButton, set permissions to read email and public profile
facebookLoginButton.SetReadPermissions("public_profile", "email");
Then simply use graphAPI to access name, ID, email and other public profile stuff.
Related
I'm working on an Android version of an app that uses Facebook for authorization and for retrieving user's friend list.
As of SDK v.2.0, it became pretty hard to get list of friends that hadn't installed your app, but I made it work and now I need to get links to friends profile pictures (avatars). But Facebook does not want to return normal IDs for friends that haven't installed the app. For example, if a friend installed an app then FB returns its ID as digits, something like this 651651616851, and if not then FB returns string of chars like "glkjrgbdjrbgjdrbhgjhLFKBfEFbFkjgnrg".
If I use digit-like ID to retrieve photo, it works, but if I try to use charlike ID, FB returns an 803 error.My question is how do I get normal IDs or how to get friends profile pictures?
This is the API call to get the pictures of friends, you can specify a (minimum) width and height:
/me/friends?fields=picture.width(400).height(400)
Please follow the link of facebook sdk about the Track Current Profile.
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
ProfileTracker profileTracker = new ProfileTracker() {
#Override
protected void onCurrentProfileChanged(
Profile oldProfile,
Profile currentProfile) {
// App code
Uri uri = currentProfile.getProfilePictureUri(200,200);
}
};
Now From Uri you can download the profile picture of user current profile.
In the new Google Sign-In API, I can get the profile photo using the following lines:
private void handleSignInResult(GoogleSignInResult result) {
if (result.isSuccess()) {
GoogleSignInAccount account = result.getSignInAccount();
String profilePhoto = account.getPhotoUrl().toString();
}
}
But, there is no method in the account object to get the cover photo, so my question is : how to get the cover photo ?
Also, I want to get the birthdate and phone number
Thanks in advance :)
The GoogleSignInAccount class doesn't provide any methods for cover photo, birthdate or phone number. You can read more in the official documantation here.
For cover photo and birthdate you can make an authorized GET request here:
https://www.googleapis.com/plus/v1/people/me?key={YOUR_API_KEY}
and you will get them in response.birthday and respone.cover.coverPhoto.url
Bear in mind that if you don't have a birthday date set, the request won't return any. And regarding the phone number, the I don't think the API offers that information.
As #Vlad said GoogleSignInAccount class doesn't provide any methods to retrieve the cover photo.
So, after a succeeded Google SignIn you could use the userId and API_KEY to make a GET request to:
https://people.googleapis.com/v1/people/{id}?personFields=coverPhotos&key={GoogleApiKey}
Replace {id} with userId and {GoogleApiKey} with API_KEY
I'm having an issue similar to this: Adding text from edit text field into an email . I am able to do what this is doing, but how could I send the email straight from a submit button, instead of having it compose an email in a default email client. This should be able to be sent with as anonymous and not need to be sent by default from an installed email client.
You need to download JavaMail API:
Download: https://java.net/projects/javamail/pages/Home
You need an SMTP server, also username and password for auth.
String host="your smtp";
final String user="from email address";//change accordingly
final String password="frm email password";//change accordingly
String to="to email";//change accordingly
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", "true");
javax.mail.Session session = javax.mail.Session.getDefaultInstance(props,new javax.mail.Authenticator() {
protected javax.mail.PasswordAuthentication getPasswordAuthentication() {
return new javax.mail.PasswordAuthentication(user,password);
}
});
//Compose the message
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(javax.mail.Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("javatpoint");
message.setText("This is simple program of sending email using JavaMail API");
//send the message
javax.mail.Transport.send(message);
System.out.println("message sent successfully...");
}
catch (MessagingException e)
{
e.printStackTrace();
}
There is no way to send an email silently, without either
letting the user know and accept it first (by using intents and an email provider)
or asking for the username and password before and using an email API as above (the user will implicitly give you the approval to send/receive emails by entering those values)
And that is a very good thing! There are too many security concerns otherwise. If you ever find a way, please post it as a bug report in android.
Workaround:
You need to use an email API such as JavaMail:
Sending Email in Android using JavaMail API without using the default/built-in app
There are some anonymous mailers that have APIs that you could use. But I would suggest you not do this. I actually agree with #DheeB 100%. I can't up vote yet.
Here is an example of one such service: http://api.temp-mail.ru/ It's in Russian but it can be translated. Again, I don't recommend but trying to answer your question.
i want to fetch user profile image and name by using user email address.
i am using facebook graph api
in my app user are able to post questions in your wall. and so he will get the responses by other users and we have only their email id so i have problem that how we access profile image and user id by using email address.
right now i am using facebook permission given below:
private static final String[] PERMISSIONS = new String[] {
"publish_stream", "read_stream", "offline_access" };
is there any other permission to access profile info by email address..
please figure out my problem...
For fetching user name and profile pic follow these steps-
Put this Permission-
public static final String[] FACEBOOK_PERMISSIONS = new String[]
{"publish_stream","email"};
Put this code in onComplete(Bundle mBundle) method -
JSONObject response = Util.parseJson(facebook.request("/me", mBundle, "GET"));
Get user name -
String userName = response.getString("username")
Now to get URL for profile pic make URL like this-
https://graph.facebook.com/userName/picture
For More details visit here.
The Facebook api doesn't allow you to find a profile given its email address. But if you have an access token that lets you read a user's wall, you should also be able to use it to obtain the profile image & display name for the author of each wall post.
You used to be able to search Facebook graph by email address to find a users name and image, but Facebook broke it and has taken months to fix it.
i am integrating the twitter in to my android application. and it logins me successfully on twitter but i do not know how to get the tweets and statuses from that so i can show it in my application. here is my code.
String CONSUMER_KEY = "XXXXXXXXXXXXXXX";
String CONSUMER_SECRET = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY";
try {
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
String url = requestToken.getAuthorizationURL();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
catch (TwitterException e){
e.printStackTrace();
}
any help will be appreciated.
You can handle the login part, without the user introducing the pin if you use signpost, and once you have the token and the verifier, you can go on with twitter4j, creating the object twitter with TwitterFactory twitterfact=new TwitterFactory();
twitter = twitterfact.getOAuthAuthorizedInstance(consumerKey, consumerSecret,accessToken);
Now you can show the timeline with twitter.getFriendsTimeLine(). It's what I do, and it works fine. I can tweet, read tweets, send private messages... and the login part doesn't fail.
As soon as you have the twitter variable correctly populated (i.e. your code throws no Exception), you can use it to twitter.getHomeTImeline() etc.
Having said that, your code looks like it only does the first part of the OAuth procedure and that you still need to have code that sets the pin the user receives and then creates a fully OAuth authorized connection.
Have e.g. a look at LoginActivity of Zwitscher (v0.65 tag).
The method getPinButton() is basically what you have above. When the user comes back, he enters the pin in an EditText and clicks on the [setPinButton()][2] which provides the 2nd part of the OAuth stuff.
OAuth keyes and tokens are then stored in preferences for later use (you need them to create authenticated Twitter instances via the TwitterFactory (see e.g. TwitterHelper.getTwitter() on how to do this).