开发者

How do I send an email or message to facebook friends through code

开发者 https://www.devze.com 2023-03-21 20:53 出处:网络
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.

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:

How do I send an email or message to facebook friends through code

What I got bac开发者_JS百科k:

{
  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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消