Facebook Webhook Feed not receiving data from live page - facebook

I have been working on this stupid app for a week and can not for the life of me figure out where I am going wrong.
I have created the app, Added Webhooks and connected the webhooks to my site. I created a log file to log all incoming connections and nothing is coming in. I can test it using the developer system and it works perfectly but nothing I do will get it work on the live page.
Basic Test Code
$challenge = $_REQUEST['hub_challenge'];
$verify_token = $_REQUEST['hub_verify_token'];
if(isset($_REQUEST['hub_challenge']) && $verify_token == '08231984'){
echo $challenge;
}
$content = file_get_contents('php://input');
$fp = fopen('test.txt', 'a');
fwrite($fp, $content);
Advanced Access Permissions: pages_show_list, public_profile, pages_manage_metadata, email
I am use to seeing a status switch in the address bar that has developer mode and live. This switch is not displayed in the address bar anymore and I have checked in multiple browsers.
I have business verified, business account manager setup and the page is added that I wish to monitor as well as myself as a user.
I am at a complete loss on how to get this thing working. Any help is greatly appreciated.

Related

Facebook Graph API get First and Last name from PSID?

I have setup a FB Webhook to notify my technicians when a user messages my business page. The notification works and I get the message and the sender's ID (PSID) but I can't seem to get the sender's first and last name per the documentation found here :
https://developers.facebook.com/docs/messenger-platform/identity/user-profile
I have been granted Advanced Access with the "Business Asset User Profile Access" as required.
The App is in Live mode (not development mode)
Messaging permissions are granted
I need to turn the returned "Sender ID (PSID)" into a First and Last name. According to the documentation, I need to send a request like this :
curl -X GET "https://graph.facebook.com/<PSID>?fields=first_name,last_name,profile_pic&access_token=<PAGE_ACCESS_TOKEN>"
So my code looks like this :
function get_basic_info($id, $access) {
$url = 'https://graph.facebook.com/'.$id.'?fields=first_name,last_name,profile_pic&access_token='.$access;
$info = json_decode(file_get_contents($url), true);
return $info;
}
I would then call the function using : $fbuser = get_basic_info($sender, $fb_access_token);
This will ALWAYS return NULL when messaging my business page from any Facebook account.... except from my personal account which owns the business page. If I message my business account from my personal account that owns the business, this is what I get back :
{"first_name":"Tim","last_name":"My_Last_Name","profile_pic":"Profile_Picture_URL","id":"My_FB_ID"}
The access token I am using is generated from the App Dashboard > My_App > Messenger (under Products, left side) > Settings > Access Tokens > Generate Token (Next to the Business Page I own).
What am I doing wrong? It works when I personally message my own business page, but not when anyone else messages. Thank you for ANY help!
So to update this with an answer for those who may be looking, here it goes.... Don't use the Sender ID (PSID) as the documentation states, use the Message ID.
function get_basic_info($id, $access) {
$url = 'https://graph.facebook.com/'.$id.'?fields=from&access_token='.$access;
$info = json_decode(file_get_contents($url), true);
return $info;
}
Usage :
$fbuser = get_basic_info($message_id, $FB_PAGE_ACCESS_TOKEN);
$fb_name = $fbuser['from']['name'];
Unfortunately, you cannot get the Profile Picture, but this is as far as I needed to get anyways.
Enjoy!

Paypal login freeze (opencart 2.1.0.2)

I added the option to login with Paypal.
I am using the Paypal standard login.
I am using sandbox for testing but the issue persists even if in real mode.
Everything is ok except after the login with the email of paypal, after I input the credentials of paypal account it goes to load the setting from paypal account that I selected (name, date of birth etc,) it goes ok and after that it freezes in the same login window (a blank window).
In the site it does not do anything and doesn't login.
I noticed that the url in the login window goes to the redirect that I had to configure. I think that maybe it's related with the redirect URL. Can anyone please check if everything is ok with the settings or if it is a known bug with this?
The full url that appears in the login windows after the credencials are submitted is:
https://www.quitandabrasil.com/index.php?route=module/pp_login/login&scope=address+profile+email+phone&code=nhZpJ2YmnH_R3HXkheGFfPErrJluZ-fDhfDFuPgqLzwYX1AmNYNEfbjPiT5D-46YO-LaPWLQU98CVEoWO5ndUMfC1XGWOMg_yAJ6ZYCK_EpC1ns4Crl6A5bDV1DdAbrTbJlRthHtbpM1NAVBJpxskbViJjGhgdczvInmmSg8BCdEupPDJzKCb2j9RLoKZl8EEeD0pVBov2zRjrq2
I have uploaded pics of the opencart config "login with paypal" and from the developer site that have the sandbox account.
DGjlR.jpg
You can refer to https://github.com/opencart/opencart/issues/3640
Change the API URLs
//$endpoint = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$endpoint = 'https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice';
//$endpoint = 'https://api.paypal.com/v1/oauth2/token';
$endpoint = 'https://api.paypal.com/v1/identity/openidconnect/tokenservice';
Comment/remove line:
//CURLOPT_USERPWD => $this->config->get('pp_login_client_id') . ':' . $this->config->get('pp_login_secret'),

404 error trying to use Facebook test user login_url

If I programmatically create a Facebook test user, the login_url for the new user doesn't work. Fetching the login_url returns a 404 error.
Pared-down example (in Python). The last two lines are where the problem shows up:
import requests
from urlparse import parse_qs
APP_ID = "<Facebook App ID>"
APP_SECRET = "<Facebook Client Secret>"
# Get app access token - this works
response = requests.get('https://graph.facebook.com/oauth/access_token',
params={'grant_type': "client_credentials",
'client_id': APP_ID, 'client_secret': APP_SECRET})
app_access_token = parse_qs(response.content)['access_token'][0]
# Create test user - this works
response = requests.post('https://graph.facebook.com/%s/accounts/test-users' % APP_ID,
data={'access_token': app_access_token, 'installed': "true"})
test_user = response.json()
login_url = test_user['login_url']
print login_url # http://developers.facebook.com/checkpoint/test-user-login/...
# Get cookied for login - see https://stackoverflow.com/a/5370869/647002
session = requests.Session()
session.get("https://www.facebook.com/", allow_redirects=True)
# Login test user - THIS FAILS
response = session.get(login_url)
print response.status_code # 404
Others have noted that you must first fetch the Facebook homepage before test user's login_url will work. We ran into that same problem, and I've included that workaround above without any luck. [Edit: added the _fb_noscript=1 query param, required starting mid-2015 for non-JavaScript test clients.] [Edit 8/2017: now removed _fb_noscript=1; no longer required, and sets a noscript cookie that makes some later FB auth requests return 500.]
I also tried opening the login_url directly in a browser:
If I'm not already logged into Facebook, I get a generic Facebook 404 page.
If I'm already logged into my developer account, Facebook warns that I'll be logged in as a platform test user, and then allows me into the test user's account.
That last point seems to confirm that the test user is being created properly and that I have the correct login_url. But of course, that's no help for automated testing. (We don't want to run tests logged into my developer account.)
Is there some other way the test user's login_url is meant to be used for automated testing?
A Facebook developer support engineer has confirmed that the test-user login_url can no longer be used for automated login of a test user, due to security changes. Apparently it's meant for manual testing.
I am, however, able to achieve automated login of a programmatically-created Facebook test user by posting to Facebook's normal login form. It seems like all you need are the email and password returned from the create-test-user API. (No other login form fields seem to be needed, though you'll still need to pick up the cookies first.)
The code below is working for me now (replacing the last two "this fails" lines of code from the original question):
# Login test user - THIS WORKS
response = session.post("https://www.facebook.com/login.php",
data={'email': test_user["email"],
'pass': test_user["password"]})
print response.status_code # 200
I haven't found this documented anywhere, and Facebook may change their login form in the future, so YMMV.

AgileToolkit OAuth add-on error 500 at facebook's mobile site

I am using the OAuth Facebook controller add-on for ATK4.
It works as expected when authenticating with Facebook from a regular desktop browser.
It works when authenticating using a mobile browser that is telling face book that it's a desktop browser.
It does not work when Facebook detects a mobile browser and redirects to m.facebook.com/dialog/oath.
What's more, is that it works fine for signups from mobile browsers (ie, when Facebook asks the user to give permission to the app).
The login flow stops with an Error 500 at:
https://m.facebook.com/dialog/oauth?redirect_uri={my_url_encoded_landing_page_where_the_OAuth_controller_lives}&scope=email&client_id={fb_app_id}
What the hell is going on here? There isn't some difference between the Facebook mobile service and the regular one that the addon isn't taking care of, or is there?
It must be something I'm doing wrong. In init() on the page that handles the FB, I am doing the following:
function init(){
parent::init();
$f = $this->add("oauth/Controller_OAuth_Facebook", array('sign_method'=>'PLAINTEXT'));
if ($fbtoken = $f->check()) {
$f->setSignatureInfo();
$f->setAuthToken($fbtoken["access_token"], $fbtoken["expires"]);
$s = $this->add("sni/Controller_SNI_Facebook");
$s->setOAuth($f);
// ...
// grab profile from SNI, database lookup, session stuff, etc
// ...
}
}
I've tried all three sign_methods, and tried leaving it alone, but that doesn't make much difference because the user is not making it back to the controller with an access token to use anyway.
I tried creating a new app with Facebook and I get the same issues with a basically vanilla configuration on that. I've only marked and specified the "Website with Facebook Login" site URL integration.
The image below was captured from Chrome after overriding the user agent to a mobile device to trigger the forward to facebook's mobile servers:
Screen shot of request
Facebook closed my bug report with them stating that it's not an issue since no one else is reporting the bug. I am removing the ATK4 tag, as I get the same issue using the example PHP code provided by Facebook on GIT.
Created dedicated example here:
http://demo.ambienttech.lv/d.html?ns=d3
Example is downloadable and includes instructions of setting up facebook app as well. See if that helps.
Try This:
<?php
class page_fb extends Page {
function init(){
parent::init();
$f = $this->add("oauth/Controller_OAuth_Facebook");
$fbtoken = $this->api->recall("fbtoken");
if ($m = $_GET["error_msg"]){
$v=$this->add("View_Error");
$v->add("Text")->setHTML("You can't connect to the application.");
$v->add("Button")->setHTML("Try again")->js("click", $this->js()->univ()->location("fb"));
return;
}
if (!$fbtoken){
if ($fbtoken = $f->check("email")){
$this->api->memorize("fbtoken", $fbtoken);
$this->api->redirect($this->api->url("/index"));
}
} else {
$f->setSignatureInfo();
$f->setAuthToken($fbtoken["access_token"], $fbtoken["expires"]);
$c = $this->add("sni/Controller_SNI_Facebook");
$c->setOAuth($f);
if (!$this->api->recall("fbuserinfo")){
$this->api->memorize("fbuserinfo", $c->getUserProfile());
}
$info = $this->api->recall("fbuserinfo");
$username = $info->username;
$img = $c->customRequest("/" . $username . "/picture?type=large");
$this->api->memorize("userimg", $img);
$this->api->memorize("userinfo", $info);
if (!$this->api->auth->isLoggedIn()){
$this->api->auth->login($info->email);
}
$this->api->redirect($this->api->url("/index"));
}
}
}
I've got the same problem, but using PHP: just using a mobile web browser is not working, giving '500 internal server error'.
I'm just asking myself if exists a parameter for the method getLoginUrl to force return a non-mobile version of the authentication page...
I reported this issue here: https://github.com/atk4/atk4-addons/issues/35
Please stay tuned and if you can, you can always make changes yourself and pull request.
I can't test and fix this because strangely I still don't have smart phone :(
Something changed in FB's mobile OAuth service that is causing the error. I ran a test with my code base on a shorter URL (ie; http://domain.net/fb/ rather than http://development.project.domain.net/fb) and it works fine. I am not entirely sure of what exactly is causing the problem as Facebook refuses to acknowledge the issue as being on their server, but I have a few possible culprits that may be triggering the error on their side, but since they don't care, I don't either, and I am providing my results for anyone else who encounters this bs.
The environment I am developing in uses semi-complex (apparently) naming scheme. The development server has its own hostname under a subdomain. The issue may be caused by the fact that there are multiple components to the host portion of the URL or simply too many characters.
The name servers for the development environment are provided by DynDNS. Facebook's mobile OAuth service may be choking on the idea of a development site being hosted on a non-permanent IP address.
I'm not going to do anymore testing on this because it really is a problem with Facebook, not my code or servers, and it will work in production.

PayPal Sandbox suddenly outputting proxy error for adaptive payments

Edit: For some reason it's working again. I did not need to log in to developer.paypal.com either. If anyone knows why, that would be useful. Thanks!
For the past few months I have been developing a site using PayPal's adaptive payments, specifically the chained payments method. I am using the embedded payment method from a site that uses SSL. The integration had been working perfectly for months until a day or two ago. It was even still working right after I imported my old sandbox accounts to the new developer.paypal.com sandbox.
After submitting the payment from the site's form, the browser spins for a minute or two. The error generated after a few minutes is the following:
The proxy server could not handle the request GET
/webapps/adaptivepayment/flow/corepay Reason: Error during SSL
Handshake with remote server
$API_UserName = "us business account from developer.paypal.com sandbox";
$API_Password = "password from developer.paypal.com sandbox";
$API_Signature = "singature from developer.paypal.com sandbox";
// AppID is preset for sandbox use
// If your application goes live, you will be assigned a value for the live environment by PayPal as part of the live onboarding process
$API_AppID = "APP-80W284485P519543T";
$API_Endpoint = "";
if ($Env == "sandbox")
{
$API_Endpoint = "https://svcs.sandbox.paypal.com/AdaptivePayments";
}
else
{
$API_Endpoint = "https://svcs.paypal.com/AdaptivePayments";
}
If I am not mistaken, I believe the error is being generated when the redirect happens from this function here:
function RedirectToPayPal ( $cmd )
{
// Redirect to paypal.com here
global $Env;
$payPalURL = "";
if ($Env == "sandbox")
{
$payPalURL = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?expType='.$_POST['expType'].$cmd;
}
else
{
$payPalURL = "https://www.paypal.com/webscr?" . $cmd;
}
header("Location: ".$payPalURL);
exit;
}
Edit: I changed the $payPalURL to "https://developer.paypal.com..." as suggested and got the following:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to
maintenance downtime or capacity problems. Please try again later.
After the recent code change this flow now requires you to log in to https://developer.paypal.com first. I am checking to see if this was intentional or is a code bug.
There appears to have been an issue with the sandbox.paypal.com server that disabled adaptive payments for a couple days. Everything seems to be functioning as it had been previously. Thank you to Dennis for his input.
Edit:
This appears to be ongoing and intermittent