0

I am getting an unexpected echo in my php error_log for echo $myData

I am trying to navigate to direct url to .php file so I believe this is why..... [I will add when I do this I see HTTP ERROR 500 due to the echo error]

The Error Log: [17-Jan-2017 22:28:59 America/New_York] PHP Parse error: syntax error, unexpected 'echo' (T_ECHO) in {Directories}get.php on line 17

PHP File

<script
  src="https://code.jquery.com/jquery-3.1.1.min.js"
  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  crossorigin="anonymous"></script>
<?php
require_once __DIR__ . '/src/Facebook/autoload.php';
    $pid = 'pageid';
    $aid = 'appid';
    $asc = 'appsecret';
    $token = $aid + '|'+ $asc;
    $fb = new Facebook\Facebook($token);
    $request = $fb->request('GET', '/'+$pid+'/Posts', array(
        'fields' => 'message,created_time,permalink_url'
      ) );
    $myData = json_encode($result)

    echo $myData;

I will be using an html page to call the above script (Which does not appear to be working)

HTML FILE:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html lang="en"> 
<head> 
<meta http-equiv="content-type" content="text/html; charset=utf-8"> 
<title>Title Goes Here</title> 
<script
  src="https://code.jquery.com/jquery-3.1.1.min.js"
  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
  crossorigin="anonymous"></script>
<script>
function myFunction(){
   alert('Window Loaded'); //THIS WORKS! EVERYTHING BELOW HERE DOES NOT SEEM TO WORK//
   var xmlhttp = new XMLHttpRequest();
     xmlhttp.onreadystatechange = function() {
          if (this.readyState == 4 && this.status == 200) {
            data = JSON.parse(this.responseText);
            document.getElementById("results").innerHTML = data;
    }
};
xmlhttp.open("GET", "get.php", true);
xmlhttp.send();
};
</script>
</head> 
<body onload="myFunction()"> //This does work to trigger my alert.
    <p id="results">
    This is my web page
    </p> 
</body> 
</html>
CBroe
  • 91,630
  • 14
  • 92
  • 150
  • You never set $facebook to anything – WizKid Jan 17 '17 at 20:28
  • I thought it was set by autoload.php in fb php sdk. :S maybe im calling it improperly... – Michael Dugas Jan 17 '17 at 20:29
  • _“Parse error: syntax error, unexpected 'echo'”_ – the line above is missing the terminating semicolon … Before you start working with any SDKs/frameworks, you should at least go learn the basics of the language to a point where you can spot minor issues like this yourself. – CBroe Jan 18 '17 at 09:00
  • Added as suggested and get this instead now: [22-Jan-2017 01:42:50 America/New_York] PHP Fatal error: Uncaught TypeError: Argument 1 passed to Facebook\Facebook::__construct() must be of the type array, integer given, called in /home/prsonlin/public_html/get.php on line 11 and defined in /home/prsonlin/public_html/src/Facebook/Facebook.php:129 Stack trace: #0 /home/prsonlin/public_html/get.php(11): Facebook\Facebook->__construct(appid) #1 {main} thrown in /home/prsonlin/public_html/src/Facebook/Facebook.php on line 129 – Michael Dugas Jan 22 '17 at 06:45

1 Answers1

1

I think you will need to create an object of Facebook class.

exp:

$fbConfig['app_id']="Fb app id";
$fbConfig['app_secret']="app secret key";
$facebook=new Facebook($fbConfig);
Suresh Dhaka
  • 82
  • 3
  • 11
  • I think you are right. Just at work right now will post results. But i remember seeing this in api. – Michael Dugas Jan 18 '17 at 02:45
  • Ok so this is a proper answer, but it does not appear to be proper for my specific situation. According to the documentation the proper process is: $fb = new Facebook\Facebook($token); $request = $fb->request('GET', '/{PAGE-ID}/Posts', array( 'fields' => 'message,created_time,permalink_url' ) ); This does seem to work for me, but i am having new problems now :( – Michael Dugas Jan 18 '17 at 03:37