Lauro182
Lauro182

Reputation: 1697

Facebook account linking, can anyone give small example code?

I'm very frustated, I can't figure out how to link accounts using the account_link button, it's making my life so hard, I posted this question before, and I thought I had understood how but I just didn't, it's driving me crazy.

Can someone please post a sample code of how to achieve this?

You get on you account linking url the GET parameters:

$token = $_GET['account_linking_token'];
$uri = $_GET['redirect_uri'];

Then you type in your credentials in the log in.

User: user
Password: pass

Click login.

You go and verify credentials, if they are correct, you link the account:

THIS IS THE SMALL BASIC EXAMPLE CODE I NEED

Then, if account linked succesfully, I redirect to the uri:

redirect($uri.'&authorization_code=myauthorizationtoken');

After this, I can retrieve PSID with the API.

Can somebody help me out please?

Upvotes: 3

Views: 2946

Answers (2)

akinmail
akinmail

Reputation: 668

Your problem is that you do not understand what account linking really means. Account linking means that you should ask this current messenger user to login on your platform thereby linking the messenger account to the user account on your platform.

The flow is just an implementation of OAUTH 2.0. Please read it up to really understand what's going on. Your job is to just

  1. Redirect the user to a login screen on your part and get the user's PSID using the endpoint provided by the documentation.
  2. Save the PSID and (optional) account linking token to the user's data model.
  3. Generate an authorization code(this is part of the OAUTH 2 flow)
  4. Redirect back to messenger.

Upvotes: 0

Bob Swager
Bob Swager

Reputation: 892

Check this out : Account Linking Failed

Use messaging_account_linking subscription for your Facebook developer application.

Upvotes: 2

Related Questions