How do I send Facebook notifications using the graph api? [duplicate] - php

I asked this on the Facebook Developers Forum with no responses.. How do I send notifications to users so they show up in the Notifications globe icon tab on the top left of a user's Facebook page? Some applications I use have their notifications show up there, but I don't see how that mechanism works in Facebook's API docs. Neither are there any permissions which seem to be required to send users notifications.

I know this is an old post - but someone might stumble on it as I did, and find it useful:
The notifications area in FB is updated by sending Requests which can be sent by using FB dialogs. The JS SDK provides the FB.ui() method to show dialogs for posting to stream, or sending a request.
More Info on FB:
http://developers.facebook.com/docs/reference/dialogs/requests/
http://developers.facebook.com/docs/reference/javascript/FB.ui/

Apparently facebook activate again the possibility to send notifications :
https://developers.facebook.com/docs/app_notifications/#ux
POST /{recipient_userid}/notifications?access_token= … &template= … &href= …

You need to post it to -
https://graph.facebook.com/
for example -
https://graph.facebook.com/{recipient_userid}/notifications? access_token= ... href= ... & template= ...

Update : Please check oneamongu's answer below. In my old answer I was referring to the custom notifications. oneamongu defined the requests structure very well below.
Old answer : Facebook Notifications were outdated by facebook about 1 year ago. Instead, you can post on a user's wall if you wanna inform him.

because when I run the query: {recipient_userid}/notifications? access_token= ... href= ... & template= ...
it's work only in facebook WEB?
I see the notification on the web facebook, but do not see it on facebook Mobile?

Related

Facebook - send chat message and/or invitation to visit an external page

I am developing an interactive website, where there is a list of users and a list of user's friends (by my website's usernames). I would like to add the possibility to connect a user to his account on facebook, in order to add the features:
a user, after indicating his facebook login credentials, should have the option to see who are his facebook friends registered is this website, and then send a chat message to someone of them with a content such as "I'm at website.com right now, join me here!".
a user should have the option to see his full contact list and then send a message (for instance a poke, an email, or other type of message... - not to the timeline!) to a subgroup inviting them to like/visit the external page;
I am more interested in the 1st option, but from what I have been reading, the facebook chat API is going to be removed by 30th april 2015 [ ref. https://developers.facebook.com/docs/chat ], with no perspectives of being replaced. Therefore I don't see other ways to implement my 1st option - is there some other way?
In respect to the 2nd option, by consulting facebook's pages [ such as: https://developers.facebook.com/docs/graph-api/reference/v2.3/friendlist, https://developers.facebook.com/docs/facebook-login/access-tokens ], I see that it is possible to get a friend list with that graph-api if I use a complicated access token. If I try to go that way, would it be possible to get the e-mails or other forms of contact after receiving those friend lists?
I would like to receive suggestions on how to implement the 1st/2nd, or both options. What are your suggestions regarding this subject?
Thank you.
(PS. different languages are welcome, although I prefer to work with php and javascript).
The Chat API is deprecated and will stop working even for old Apps after April 2015. There will be no replacement. How to invite users to an App or Website is explained here: https://developers.facebook.com/docs/apps/faq#invite_to_app
the friendlist endpoint is actually not for getting access to the friends, but only to the...well, friendlists ;) - /me/friends would be the correct endpoint, but you will only get friends who authorized your App. You can read more about that in this thread: Get ALL User Friends Using Facebook Graph API - Android
Btw, prefilling messages is not allowed anyway, even if the Chat API would still exist you would need to let the user write the invite message. So you can just use the Send/Message Dialogs. You don´t even need to authorize the user for that.

How to send a friend request through the PHP Facebook API

I'm working on a website where I'd like to allow a user to send a Facebook friend request to another through the website. I have the Facebook account information for both. Is this possible? I know it was in the old version of the GRAPH API and also using FBML, both of which are outdated now.
Cheers!
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friendrequests#publish
You can't publish using this edge. The Friends Dialog should be used if you want to integrate the ability to add someone as a friend in your app.
The Friend Dialog was removed with v2.0, so there is no way anymore.

Can a page tab post to a user's wall?

I have a Facebook application used as a tab in a fan page, that displays different information depending on whether tha user is a fan of that page or not.
Now I've been asked to have it post a message to a user's wall if they perform certain action (follow a link or whatever), and so far I haven't found a way to do that. All the documentation I have found refers to stand alone apps, and I've even seen it suggested (in the FB forums) that you can't get the auth token from an app.
So, i still think it can be done, but how?
If a user has authorized your app, you can post to her wall using the PHP SDK. See the PHP SDK api documentation for examples.
All apps have to be iframe apps now, so loading the JS sdk should be fine.
You have to get permissions first ->
http://developers.facebook.com/docs/authentication/#applogin
Then you can post using php with what Dhiren said, or, post with the fb.api function with JS ->
http://developers.facebook.com/docs/reference/javascript/FB.api/
Let me know if you need an example script.
Cheers

Is there a way for users of my website to invite their friends via Facebook Connect or the API?

Working with the Facebook API makes my ears bleed, but nonetheless I've got a specific problem here which I'm hoping someone can find a solution for. I'm using the Facebook PHP SDK to allow users of my website to link their FB account with their website account, so they can return later and log in with one click (by storing their OAuth tokens in my database). This is all working fine - what I now want is to be able to provide users with the facility to invite/recommend their friends to my site, using a form on my site.
I've tried FBML examples from many places including here - I've managed to get an invitation form to display but try as I might, all I can get it to generate is an invitation to my application, which isn't relevant. The app exists only so that I have an OAuth ID/secret to use with the Graph API. I want to invite the user's friends to my website, or at the very least to a Facebook Page plugging my website. But seemingly including this FBML on my page will only generate application invites.
My question: is there any way to accomplish this? Can I invite the user's friends to my site (ie. to a specific URL), or invite them to my FB Page? Am I approaching this from the wrong angle?
Any advice would be much appreciated. If you'd benefit from any further info, please let me know. Many thanks,
Biggs
Right. It turns out after much tearing of hair, the example I gave was the right one. The invite generates an "Application Invite", but this is not like other app invites. When the recipient clicks "Accept" they are sent to the URL you specify (in this case, my website). The "App" then disappears from their request page - it does not appear in their profile like a normal app. So a horribly nonsensical process but a positive outcome. Phew!
It seems like sending a Facebook message is the way to go at this point (Jan 2013).
https://developers.facebook.com/docs/reference/dialogs/send/
In general, applications on Facebook should use Requests when
communicating in game status (its your turn), inviting people to use
an application, or sending messages to multiple people.
FB.init({appId: 'YOUR_APP_ID', xfbml: true, cookie: true});
FB.ui({
method: 'send',
name: 'Check out this site!',
description: 'This is the best site ever!',
link: 'http://www.example.com/refer',
picture: 'http://www.example.com/image.jpg'
});
Why not go for this open source inviter which can get your work done quick . also if you are using a cms they might have already made the plugin for your cms. http://openinviter.com/

Change Facebook profile image via API

Is it possible to change someone's profile picture via the Facebook API?
The Graph API discusses POSTing a picture to an account but I see nothing related to the direct altering of a user account. I suspect they only recognize GET requests under their RESTful API (for the user area). Thus, a no.
That's just information gleaned from the Facebook API docs, however. I could be missing something though.
not possible: Facebook API/PHP - Is it possible to change a user's profile image via FB Graph API?, and also my own experience.
This feature is not possible, period. Although you can upload an image to the Graph API and then redirect the user to the permalink of that post :)
It's possible by adding makeprofile=1 at the end of uploaded photo url. You can find example (PHP) and demo here: http://4rapiddev.com/facebook-graph-api/php-change-facebook-profile-picture-with-graph-api/

Categories