Birthday of Friend's using facebook api 2.0 - facebook-graph-api

I am trying to get birthday of my friends, those who have installed my sample app. Below is my code.
new Request(simpleFacebook.getSession(), "/" + id, null, HttpMethod.GET,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
String rawResponse = response.getRawResponse();
AppLog.showLog(TAG, "Friend response is " + rawResponse);
}
}
).executeAsync();
But in response there is no any "birthday" filed.
I also used simplefacebook library. Using below code
PictureAttributes pictureAttributes = Attributes.createPictureAttributes();
pictureAttributes.setType(PictureAttributes.PictureType.SQUARE);
pictureAttributes.setWidth(250);
pictureAttributes.setHeight(250);
Profile.Properties properties = new Profile.Properties.Builder()
.add(Profile.Properties.NAME)
.add(Profile.Properties.BIRTHDAY)
.add(Profile.Properties.PICTURE)
.add(Profile.Properties.ID)
.build();
simpleFacebook.getProfile(id, properties, new OnProfileListener() {
#Override
public void onComplete(Profile response) {
String id = response.getId();
String name = response.getName();
String birthday = response.getBirthday();
String pictureUrl = response.getPicture();
AppLog.showLog(TAG, "Single friend Detail: " + id + "\t" +
name + "\t" + birthday + "\t" + pictureUrl);
FbFriendsDao fbFriendsDao = new FbFriendsDao(LoginActivity.this);
fbFriendsDao.openForWrite();
fbFriendsDao.insertFriends(new FbFriendDto(id, name, birthday, pictureUrl));
}
#Override
public void onException(Throwable throwable) {
super.onException(throwable);
}
#Override
public void onFail(String reason) {
super.onFail(reason);
}
#Override
public void onThinking() {
super.onThinking();
}
});
But it gives null in birthday filed.
Please help to solve this problem. Thanks in advance.

As #luschn mentioned, all friends_* permissions have been removed, including friends_birthday.
However it is still possible to get some data if:
The friend you want the birthday for is also a user of your app
The friend has provided the user_birthday permission (note you'll need this approved by FB)
You can do this by adding "birthday" to the fields key in me/friends:
me/friends?fields=id,name,birthday
Alternatively, you could simply save the user data to your own database when the user signs up and then retrieve it later, which would give you exactly the same outcome.

Check out the changelog: https://developers.facebook.com/docs/apps/changelog
All friends_* permissions have been removed
That includes friends_birthday, so it is not possible to get the birthday of a friend anymore.

Related

Contact phone numbers Lync SDK 2013

Hello I'm using Lync SDK 2013, to display number phones from contact in ListBox, and use the Items (phone number) to call this number by my API. So i did a WPF application, that contains just a ListBox, and 2 buttons (Call - Hang up). My apllication is added as custom command in Lync, in RightClick in the contact. and it doesn't have any Lync Controls. So what i want to do is: if i Right Click on the contact, my application launches and gives me the number phone List in the ListBox. I did it with a WPF that contains the controls: ContactSearchInputBox (to search a contact) and ContactSearchResultList and it works very Well, I don't know how to do it without controls.
Any One Can Help Me !!!! :(
You need to read and understand the Lync SDK 2013 Lync Contact documentation.
If you wish to "simulate" the Lync Contact "search" (as per the Client search) then you need to look into the search API.
The other concepts you need to understand is the results returned from all the API are NOT guaranteed to return all the Lync Contact data that asked for.
There is no way with the Lync SDK to "load" all the contact information which is what most people seem to not understand.
The results returned are what the local cache has and no more. To get the all the Lync Contact information you need to understand the ContactSubscription model.
For each Lync Contact that you wish to be notified of field updates (or loads) you "subscribe" to the Lync Contact and then you will be notified via the Contact.ContactInformationChanged event.
So your UI must to able to auto-update the information as the fields get loaded / updated from any initial value returned from any Lync Contact value.
public partial class ChoosePhoneNumber : Window
{
LyncClient lync_client;
Contact contact;
ContactSubscription contact_subscription;
List<ContactInformationType> contact_information_list;
ContactManager contact_manager;
public ChoosePhoneNumber()
{
InitializeComponent();
connect_lync();
get_subscribed_contact(this.contact);
}
}
private void connect_lync()
{
try
{
lync_client = LyncClient.GetClient();
contact_manager = lync_client.ContactManager;
}
catch (ClientNotFoundException)
{
MessageBox.Show("Client is ot running", "Error While GetClient", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void get_subscribed_contact(Contact contact)
{
List<object> contact_phone_numbers_list = new List<object>();
contact_information_list = new List<ContactInformationType>();
contact_information_list.Add(ContactInformationType.ContactEndpoints);
contact_information_list.Add(ContactInformationType.DisplayName);
contact = contact_manager.GetContactByUri("number"); // I put here the number phone of a contact in my list
contact_subscription = LyncClient.GetClient().ContactManager.CreateSubscription();
contact_subscription.AddContact(contact);
contact.ContactInformationChanged += Contact_ContactInformationChanged;
contact_subscription.Subscribe(ContactSubscriptionRefreshRate.High, contact_information_list);
List<object> endpoints = (List<object>)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
var phone_numbers_list = endpoints.Where<object>(N => ((ContactEndpoint)N).Type == ContactEndpointType.HomePhone ||
((ContactEndpoint)N).Type == ContactEndpointType.MobilePhone || ((ContactEndpoint)N).Type == ContactEndpointType.OtherPhone
|| ((ContactEndpoint)N).Type == ContactEndpointType.WorkPhone).ToList<object>();
var name = contact.GetContactInformation(ContactInformationType.DisplayName);
if (phone_numbers_list != null)
{
foreach (var phone_number in phone_numbers_list)
{
contact_phone_numbers_list.Add(((ContactEndpoint)phone_number).DisplayName);
}
conboboxPhoneNumbers.ItemsSource = contact_phone_numbers_list;
}
}
private void Contact_ContactInformationChanged(object sender, ContactInformationChangedEventArgs e)
{
var contact = (Contact)sender;
if (e.ChangedContactInformation.Contains(ContactInformationType.ContactEndpoints))
{
update_endpoints(contact);
}
}
private void update_endpoints(Contact contact)
{
if ((lync_client != null) && (lync_client.State == ClientState.SignedIn))
{
ContactEndpoint endpoints = (ContactEndpoint)contact.GetContactInformation(ContactInformationType.ContactEndpoints);
}
}
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
App.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException; ;
try
{
string argsParam = "Contacts=";
if (e.Args.Length > 1)
{
if (e.Args[2].Contains(argsParam))
{
var contacts_sip_uri = e.Args[2].Split('<', '>')[1];
Params.contacts = contacts_sip_uri;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Reading Startup Arguments Error - " + ex.Message);
}
}
private void Current_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
string message = e.Exception.Message;
if (e.Exception.InnerException != null)
{
message += string.Format("{0}Inner Exception: {1}", Environment.NewLine, e.Exception.InnerException.Message);
}
MessageBox.Show(message, "Unhandled Exception", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Params is a public static class that contains just contact as public static string contacts { get; set; }
public static class ParamContact
{
public static string contacts { get; set; }
}

Invalid relationship

I've got a class Account like (in Groovy):
#NodeEntity
class Account {
#GraphId
Long id
String accountId
String firstname
String lastname
#Relationship(type = 'HAS_INVITED', direction = Relationship.INCOMING)
List<Account> invitations = []
String getName() {
if (firstname && lastname) {
return "$firstname ${lastname[0]}."
}
return email
}
#Override
int hashCode() {
if (id) {
return id.hashCode()
} else {
return 0
}
}
#Override
boolean equals(Object obj) {
if (obj.is(this)) {
return true
}
if (obj instanceof Account) {
return obj.id == id
}
return false
}
#Override
String toString() {
"$email"
}
}
In my database, I've created 2 accounts Chris and Bob. Bob has invited Chris like below.
To load accounts, I've written this repository:
interface AccountRepository extends GraphRepository<Account> {
Account findByAccountId(String id)
Account findByEmail(String email)
}
Now, my problem: when I load the Chris account I get Bob as invited (it's ok). But, I've got Chris as invited for Bob and I don't understand why.
For me, I should have one invitation for Chris but 0 for Bob.
Any existing setter for INCOMING relationships must be annotated to avoid ambiguity during mapping. This is specified in the documentation:
The direction attribute on a #Relationship defaults to OUTGOING. Any fields or methods backed by an INCOMING relationship must be explicitly annotated with an INCOMING direction.
http://neo4j.com/docs/ogm-manual/current/reference/#reference:annotating-entities:relationship

Accessing public information using a specific userID on facebook graph api

Someone is logged into my app. I need to display some profiles of people that might not be on this person's friends list. Is that possible, or is it a privacy issue. A person's "public profile" should be accessible right?
I tried to get the first name, profile picture and gender
Bundle parameters = new Bundle();
parameters.putString("fields", "first_name,gender");
try {
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + user.getUserID(),
parameters,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject facebookResponse = response.getJSONObject();
try {
final String first_name = facebookResponse.getString("first_name");
final String gender = facebookResponse.getString("gender");
Bundle params = new Bundle();
params.putBoolean("redirect", false);
params.putString("type", "square");
params.putInt("width", 200);
params.putInt("height", 200);
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/" + user.getUserID() + "/picture",
params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject facebookResponse = response.getJSONObject();
try {
JSONObject data = facebookResponse.getJSONObject("data");
String url = data.getString("url");
Name.setText(first_name);
Gender.setText(gender);
mNetworkImageView.setImageUrl(url, mImageLoader);
facebookResponseListener.updatedUserObject(first_name, url, gender, pos);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
).executeAsync();
} catch (Exception uee) {
uee.printStackTrace();
}
all of this is inside the getView() if a listview (it's where I display the profiles). While testing, I'm getting all the information of the friends of the logged in person, but the "gender" property in the response object is missing from the non-friend. Only the name and userID is being returned.
It's all explained in the docs (https://developers.facebook.com/docs/facebook-login/permissions):
gender & locale can only be accessed if:
The person queried is the person using the app.
The person queried is using the app, and is a friend of the person
using the app.
The person queried is using the app, is not a friend of the person
using the app, but the app includes either an app access token or an
appsecret_proof argument with the call.

Add recipients to existing recipient list with C# code - Sitecore Email campaign manager

I want to add new recipients to existing recipientlist using code. I tried with below code but it didnt work.
TargetAudience recipientList = Factory.GetTargetAudience("RecipientListId");
if ((recipientList != null))
{
Contact contact = //I dont know how to create object for this, because it is protected class
contact.Profile.Email = "my Email";
contact.Profile.Name = "My Name";
contact.Profile.FullName = "Full Name";
recipientList.Subscribers.Add(contact);
}
Please help me to acheive this,
Thanks in advance
You can get a contact from the username of the user.
This method gets the contact by email address and contains code to get the username from the email address.
public Contact GetContact(string email)
{
// managerRoot is the top level ECM item
ManagerRoot managerRootFromId = Factory.GetManagerRootFromID(managerRoot.ID.ToString());
var username = Util.AddressToUserName(email);
string commonDomain = managerRootFromId.Settings.CommonDomain;
string fullName = commonDomain + "\\" + Util.AddressToUserName(username);
if (User.Exists(fullName))
{
return Contact.FromName(fullName);
}
return null;
}
You should then be able to add the Contact to the subscription list.
Or once you have the Contact you can set the profile values and use the subscribe method.
contact.InnerUser.Profile["Fullname"] = string.Format("{0} {1}",person.Firstname,person.Surname);
contact.Subscribe(subscriptionLists);
You can also add ECM users by using the following code supplying the email address as the localname.
protected static Contact CreateAnonymousECMUser(string localName, ManagerRoot root)
{
Contact contact = (Contact)null;
if (root != null && !string.IsNullOrEmpty(localName))
{
string commonDomain = root.Settings.CommonDomain;
Assert.IsNotNullOrEmpty(commonDomain, EcmTexts.Localize("The Common Domain setting is not set.", new object[0]));
string str = commonDomain + "\\" + Util.AddressToUserName(localName);
while (User.Exists(str))
str = str + "_";
string password = new PasswordGenerator()
{
MinimumCharacters = 14
}.Generate();
System.Web.Security.Membership.CreateUser(str, password, localName);
contact = Contact.FromName(str);
contact.Profile.ProfileItemId = root.Settings.SubscriberProfile;
contact.Profile.Save();
}
return contact;
}

Extracting users friend list from facebook graph api v2.3

I am using facebook SDK 4.0.1. I gave permission for user_friends but I am not able to get friend list of the user. I am getting the count of the user's friends but I want the name of the user's friends and ids
private FacebookCallback<LoginResult> mcallback = new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
accessToken = loginResult.getAccessToken();
Log.d("Access Token", accessToken.toString());
Profile profile = Profile.getCurrentProfile();
// Log.d("PROFILE","PROFILE IMAHE"+profile.getName());
displayWelcomeMessage(profile);
GraphRequestBatch batch = new GraphRequestBatch(
GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject jsonObject, GraphResponse response) {
try {
SharedPreferences.Editor editor = prefs.edit();
editor.putString(Constant.KEY_ID,jsonObject.getString("id"));
editor.putString(Constant.KEY_USER_NAME,jsonObject.getString("name"));
editor.putString(Constant.KEY_USER_FNAME,jsonObject.getString("first_name"));
editor.putString(Constant.KEY_USER_LNAME,jsonObject.getString("last_name"));
// hometown = jsonObject.getJSONObject("hometown");
// editor.putString(Constant.KEY_USER_HOMETOWN,hometown.getString("name"));
editor.putString(Constant.KEY_USER_EMAIL,jsonObject.getString("email"));
editor.putString(Constant.KEY_USER_GENDER,jsonObject.getString("gender"));
// editor.putString(Constant.KEY_USER_DOB,jsonObject.getString("birthday"));
editor.commit();
// town = hometown.getString("name");
// personId = jsonObject.getString("id");
// gen = jsonObject.getString("gender");
// email = jsonObject.getString("email");
Log.d("RESPONCE", "RESPONCE user=" + jsonObject.toString());
Log.d("RESPONCE", "RESPONCE =" + response.toString());
}
catch (JSONException e) {
e.printStackTrace();
}
}
}),
GraphRequest.newMyFriendsRequest(accessToken, new GraphRequest.GraphJSONArrayCallback() {
#Override
public void onCompleted(JSONArray jsonArray, GraphResponse response) {
//Lo Application code for users friends
Log.d("RESPONCE FRIEND", "RESPONCE FRIEND=" + jsonArray.toString());
Log.d("RESPONCE FRIEND", "RESPONCE =" + response.toString());
response.getJSONArray();
}
}));
batch.addCallback(new GraphRequestBatch.Callback() {
#Override
public void onBatchCompleted(GraphRequestBatch graphRequests) {
// Application code for when the batch finishes
}
});
batch.executeAsync();
Since v2.0 of the Graph API, it is only possible to get friends who authorized your App too - for privacy reasons. More information can be found in this and many other threads about that exact same question: Facebook Graph Api v2.0+ - /me/friends returns empty, or only friends who also use my app