Facebook Request over PHP - facebook

I'm trying to generate a User to User Request out of my App in Facebook.
The thing is, that I only find tutorials which use JavaScript. But I want to send a Request to a Friend out of my PHP environment.
Do I have to use te Api Call somehow?
Thanks for your help!

There isn't a PHP Call available to send requests to a user, you can only use the Requests JavaScript API call for this. This is there to prevent abuse of requests - by preventing automatic sending of requests in the background without the user's consent.

Related

How to test a custom API which implements OAuth without building a front-end?

I'm building a Rails API with a proper front-end to go along with it (probably React). I'm currently implementing the API and haven't written a single line of front-end. I'm trying to implement OAuth with Facebook as explained in #a14m's answer for this post.
However the problem is that my API would require an authentication code so that it can exchange it for an access token with Facebook. As far as I understand, the code is obtained via a login dialog on the front-end. Now I want to test whether or not my API is getting a valid access token from Facebook in exchange for the code. But to get the code I have to open a dialog on the "front-end" which I have not implemented yet.
Any way I could open the dialog for Facebook login and get the code without writing the front-end? I probably think Postman would help but I don't know how. Also if there is a way to obtain the token without triggering the dialog would also get my job done. So I just want a way to access the code without a front-end.
You can definitely use Postman for this. I write Rails APIs often and I always use Postman to hit the endpoints without having a front-end. All you have to do is find out what you need to send to the Facebook API and set it up as a form body on Postman.

User to User Messaging with Facebook API

I am trying to write an application that allows the user to authenticate via Facebook and then allows the user to send messages to their contacts through my platform, but the documentation doesn't seem to indicate any way of doing so. I see where the documentation for Web allows a pop-up share dialog, but I want a pure UI if possible that, after authenticating with Facebook, doesn't use Facebook's UI anymore.
Ideally, I'd like to be able to send the messages from the server instead of through the JavaScript API.
Is this possible?
The Send Dialog is the only way to send messages from User to User. You cannot send messages with the API, each message has to be written and committed by the user.
Btw, you do not need authorization to use the Send Dialog, just the JavaScript SDK.

Issue creating app requests on facebook http graph api

When trying to create app requests through facbeook http graph api I'm getting the error "(#2) Failed to create any app request".
As described in the documentation (https://developers.facebook.com/docs/graph-api/reference/user/apprequests/) I'm using the URL https://graph.facebook.com/{userid}/apprequests setting in post the access token, a title and a message. I've tried different combinations of parameters just to check if I needed anything else, but just if I remove access token and/or title I get different errors.
In addition to that, if I use my own userid, instead of other userid (obviously a friend) that I want to send the request to, there's no error at all, but no request is created.
I don't think it may be related with permissions because both users (source and destination of the request) are admin, developer or tester of the app.
Thank you
Just in case anyone needs it, the problem is that user apprequests can only be created if using any facebook ui methods. That's why in this thread Apprequest of Android Facebook sdk 3.0 comment 1 advices to use webdialog instead of sending the request in code.
More on this topic, I've been researching and I found out that I started with my app really long ago (using API lower than 2.3) so I didn't need to set the category as "game" to be able to send apprequests. I updated its category and after multiple tests I've found the following scenarios:
Javascript API works correctly to send requests in my app
Graph API fails to send requests if using user auth token getting the same error as before
Graph API is able to send requests if using app auth token (from app_id + app_secret)
As far as I've read, there's no limitation in using either kind of auth tokens for apprequest calls.
In addition, my app will be running in web, desktop and mobile. The scenario in which I'm using graph API directly is desktop for obvious reasons (there's other APIs tor the other platforms). As recommended in the FB api documentation, the app secret should not be included in binary code deployed to users, so I would need to use the user auth token.
Any help would be apreciated
Thanks

How can I allow users with their own slack account/company login to their slack account in my app

Everything I have read (e.g. https://api.slack.com/docs/oauth) makes it seem as though I can only build an app that integrates with a Slack team I manage. E.g. I have to create my Slack Client ID .. etc ... and then I can oAuth users for my team.
What I want to do is allow my app's users to login to my app using their Slack login (for their Slack team I do not control or have access to.) I don't want to force my users to generate a Client ID to use my app. I want them to login the same way Google Login or Facebook Login works.
The closest thing I have found is a "login with slack" HTML button, but I'd like to do it in iOS using Swift.
Is that possible?
Sadly, that's not possible. For google or facebook, the way authentication works is that they provide you a mobile API which handles the communication between your app and their web service. So you task is simply adopt that API, make simple function call and retrieve information for user from the API. For example, the facebook button is provided by the API.
However from a look at slack site, they only have RESTful API documented. So in this case, you have to handle the passing and storing of parameters by yourself, and send HTTP request manually. You can have a look at Alamofire framework, which is the best choice for making HTTP request. Basically, you have to send needed parameter with the specific url though HTTP request to perform a log in action, and you have to parse the respond data and then see if the login is successful or not, etc
Thanks to some help from friends it looks like the answer is yes.
You must first make sure you "Distribute App"
Then set up the permissions you require and "install app" (which is a bit not "smart" since you can accidentally add conflicting permissions and get an error when trying to install).
Once that is done you will get an Auth Token and can make requests for any user to login using oAuth.
You can also trigger a sign in request like so:
https://slack.com/oauth/authorize?client_id=[client id]&scope=identity.basic
Edit: For future Googlers, Slack now also provides a specific documentation page for this type of OAuth grant/login: Sign in with Slack

Facebook - Send Message To Friend(s) with / or without API in PHP / cURL?

Apparently with the Facebook API, you can only read a users inbox, not send messages. Without doing a Javascript send dialog.
I am creating a simple script with twilio where I can call in, and save a message. Then have that message be emailed to a friend, or myself.
That's done, and easy, but people don't check their emails that often as they check a Facebook message.
Question:
Is it possible with the Facebook API, or using cURl or some other method in PHP to automatically login into my facebook account, and send a message to a friend?
My personal facebook, not anyone, but have my email and password passed into it and have the script do this automatically?
Is this possible, or against Facebooks TOS to have php remotely access and use my FB account?
If someone were looking for a similar solution today, they can request access to integrate Twilio with the Facebook Messenger API here.
If you send an SMS with Twilio, for example:
https://www.twilio.com/docs/api/rest/sending-messages
https://www.twilio.com/docs/api/rest/sending-messages
from twilio.rest import TwilioRestClient
# put your own credentials here
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
AUTH_TOKEN = "[AuthToken]"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
client.messages.create(
to="+15558675309",
from_="+15017250604",
body="Hey Jenny! Good luck on the bar exam!",
media_url="http://farm2.static.flickr.com/1075/1404618563_3ed9a44a3a.jpg",
)
You would then be able to integrate with Facebook Messenger with little change to your Twilio code.
You can try Nimrod : https://www.nimrod-messenger.io/
Your friends will have to register and give you their API keys if you want to send messages to them.