0

I've been trying read(cut) my way through the jungle of Facebook posts about sending a message or email to my Facebook friends through code. So far I have found the Facebook REST API: https://developers.facebook.com/docs/reference/rest/notifications.sendEmail/

When testing with the testing tool it only works sending mails to the account that you are logged in with. Not the accounts that has granted permissions to the application. All I'm getting back for the other users is:

"error_code": 200,
"error_msg": "Permissions error",
"request_args": {...}

This API is deprecated and will be replaced by the GRAPH API: http://developers.facebook.com/docs/reference/api/

In this API it doesn't seem to be any email sending but message exist:

http://developers.facebook.com/docs/reference/api/message/

But that only allows reading messages... The only way of sending things is to post to the users wall and that is something that I do NOT want to do.

So my questions are:

  1. Is it or will it be allowed to send emails or messages?

  2. If yes where do I start? What API should I use(JAVA)?

  3. Is there a way of doing this through Janrain, the only thing I found was to do it on the wall?

Bonus question =)

  1. Why do Facebook make it so hard to find information about this?

****EDIT*****

To test Graph API I used the testing tool located at https://developers.facebook.com/tools/explorer/ . There I entered my facebook id and performed a GET:

https://graph.facebook.com/my.id

What I got back was some information about my account but no email

{
id: "mypersonalfacebookid",
name: "my name",
first_name: "my",
last_name: "name",
link: "http://www.facebook.com/my.name",
username: "my.name",
gender: "male",
locale: "en_US",
type: "user",
}

This is ok since i did not enter any Access Token. The second step was to enter the Access Token for my application from https://developers.facebook.com/apps, which has been granted for user my.name to access my.name's email: priv

What I got back:

{
  id: "mypersonalfacebookid",
  name: "my name",
  first_name: "my",
  last_name: "my name",
  link: "http://www.facebook.com/my.name",
  username: "my.name",
  work: [
    {
      employer: {
        id: "11111111111111",
        name: "CooolCompany.com",
      }
      with: [
        {
        },
      ]
      from: {
      }
    },
  ]
  education: [
    {
      school: {
        id: "11111111111",
        name: "Studied Computer Science",
      }
      type: "College",
    },
  ]
  gender: "male",
  email: "my.name@gmail.com",
  timezone: 2,
  locale: "en_US",
  verified: true,
  updated_time: "2011-07-20T17:12:26+0000",
  type: "user",
}

Cool the email is there but if I do this for some other user that has granted the same privs for his/her account:

{
  id: "xxxxxx",
  name: "My Friend",
  first_name: "My",
  last_name: "Friend",
  link: "http://www.facebook.com/my.friend",
  username: "my.friend",
  hometown: {
    id: "12345",
    name: "Cool Town",
  }
  location: {
    id: "1111111",
    name: "Somewhere",
  }
  gender: "female",
  locale: "en_US",
  updated_time: "2011-06-29T19:21:38+0000",
  type: "user",
}

No email here! Why?

jakob
  • 5,979
  • 7
  • 64
  • 103

2 Answers2

3

First of all, it is absolutely not true that Facebook makes it hard to find information about their API's. In fact, you're probably calling this upon yourself by using the REST API, since that one has been marked as deprecated.

I would advise you to use the GRAPH API, and read up on authenticating using OAuth.

In your request, you have to ask for permission to do additional actions (other than the standard permissions). My guess is you're not asking for the permission to send a message or email.

  • Hello Rick! First of all I must disagree with you. If you search for this question at stackoverflow or google you will get a huge amount of people with the same dilemma. Second, I tested the Rest API only because there was no way of doing this with the Graph API. Third, I have email permissions for that user since I ask for them when connecting my app with FB. – jakob Jul 19 '11 at 13:34
  • I have also access to all the users friends(ids) through janrain but not their email, so if you know how to do it with Graph API, please point me in the right direction. – jakob Jul 19 '11 at 13:37
3

Q. How to send an email to FB user?

  1. Create an app.
  2. Have the user auth the app (ask for access to email address in GDP - permissions).
  3. Use your email solution to send an email to the user.
  4. Done.

Check out the graph API explorer: https://developers.facebook.com/tools/explorer/

C @ Facebook

CPD
  • 427
  • 2
  • 11
  • Thank you for your answer! I'm still having issues with this. The application has following permissions for me and another user: Access my basic information, Send me email, Post to my Wall, Access my data any time and when using the graph with the applications Access Token and doing https://graph.facebook.com/[my id] I'm getting the email but when doing this for another user's id I'm not. Could you please help me further to get this? – jakob Jul 19 '11 at 19:16
  • Without seeing what you're doing, it's hard help you further. Can you give more detail? – CPD Jul 21 '11 at 13:50