Jump to content

dweb

Members
  • Posts

    122
  • Joined

  • Last visited

Everything posted by dweb

  1. Hi I'm having some issues working with the facebook sdk5 so im wondering if anyone has had the same issues, i've looked on google and can only see some issues when used with a framework like codeigniter When I run my login.php script it shows the facebook login button and sucessfully redirects me to the callback page, and shows some metadata, but following that comes some errors Notice: Undefined variable: config in C:\www\fb\fb-callback.php on line 52 Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Access token metadata contains unexpected app ID.' in C:\www\fb\facebook-php-sdk-v4-5.0.0\src\Facebook\Authentication\AccessTokenMetadata.php on line 329 Facebook\Exceptions\FacebookSDKException: Access token metadata contains unexpected app ID. in C:\www\fb\facebook-php-sdk-v4-5.0.0\src\Facebook\Authentication\AccessTokenMetadata.php on line 329 oddly these errors show despite me taking the code directly from the facebook developers area, and the only things i've added to their code sample is the top 2 lines session_start(); require_once ('facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.php'); my scripts are login.php <?php session_start(); require_once ('facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.php'); $fb = new Facebook\Facebook([ 'app_id' => '', 'app_secret' => '', 'default_graph_version' => 'v2.4', ]); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; // Optional permissions $loginUrl = $helper->getLoginUrl('http://192.168.0.4/fb/fb-callback.php', $permissions); echo '<a href="' . htmlspecialchars($loginUrl) . '">Log in with Facebook!</a>'; ?> fb-callback.php <?php session_start(); require ('facebook-php-sdk-v4-5.0.0/src/Facebook/autoload.php'); $fb = new Facebook\Facebook([ 'app_id' => '', 'app_secret' => '', 'default_graph_version' => 'v2.4', ]); $helper = $fb->getRedirectLoginHelper(); try { $accessToken = $helper->getAccessToken(); } catch(Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch(Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } if (! isset($accessToken)) { if ($helper->getError()) { header('HTTP/1.0 401 Unauthorized'); echo "Error: " . $helper->getError() . "\n"; echo "Error Code: " . $helper->getErrorCode() . "\n"; echo "Error Reason: " . $helper->getErrorReason() . "\n"; echo "Error Description: " . $helper->getErrorDescription() . "\n"; } else { header('HTTP/1.0 400 Bad Request'); echo 'Bad request'; } exit; } // Logged in echo '<h3>Access Token</h3>'; var_dump($accessToken->getValue()); // The OAuth 2.0 client handler helps us manage access tokens $oAuth2Client = $fb->getOAuth2Client(); // Get the access token metadata from /debug_token $tokenMetadata = $oAuth2Client->debugToken($accessToken); echo '<h3>Metadata</h3>'; var_dump($tokenMetadata); // Validation (these will throw FacebookSDKException's when they fail) $tokenMetadata->validateAppId($config['app_id']); // If you know the user ID this access token belongs to, you can validate it here // $tokenMetadata->validateUserId('123'); $tokenMetadata->validateExpiration(); if (! $accessToken->isLongLived()) { // Exchanges a short-lived access token for a long-lived one try { $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); } catch (Facebook\Exceptions\FacebookSDKException $e) { echo "<p>Error getting long-lived access token: " . $helper->getMessage() . "</p>"; exit; } echo '<h3>Long-lived</h3>'; var_dump($accessToken->getValue()); } $_SESSION['fb_access_token'] = (string) $accessToken; // User is logged in with a long-lived access token. // You can redirect them to a members-only page. // header('Location: https://example.com/members.php'); ?> thanks very much
  2. Hi all I have the following jquery $(document).find('.files li:visible:first').css('background','blue'); but it doesn't seem to work. Oddly if I remove 'visible' and use $(document).find('.other li:first').css('background','blue'); it works. How can I correct my issue as I really need it to apply the code to the first visible element Thanks
  3. Thanks again. Going forward, is it better to use bindParam or bindValue
  4. thanks i'll try that
  5. Thanks, i'll give that a go. For code consitancy i'd tried to keep it similar to my other methods
  6. Sure that makes perfect sense. But do you see no logical way to overcome this issue using the method i'm trying to? From what i've read online, when benchmarked tests were done, a single insert outperformed multiple inserts, so I figured it might be best to try and do it this way for performance reasons.
  7. Hi all I am trying to use a prepared statement to insert an array of users, my array is Array ( [0] => 1[1] => 4 [2] => 7 ) This works fine, and inserts no problem, but for some reason when it runs the following loop foreach($users as $user) { $stmt->bindParam(':user_id', $user_id, PDO::PARAM_STR); $stmt->bindParam(':no', $user, PDO::PARAM_STR); } it's using just 1 user record and duplicating it. So rather than inserting 3 records 1 4 7 it just inserts all 3 records with 7 The full code is $sql = 'INSERT INTO users (user_id, no) VALUES '; $i=0; $count = count($user_array); foreach($users as $user) { $i++; $sql .= "(:user_id,:no)"; if($i < $count) { $sql .= ","; } } $stmt = $conn->prepare($sql); foreach($users as $user) { $stmt->bindParam(':user_id', $user_id, PDO::PARAM_STR); $stmt->bindParam(':no', $user, PDO::PARAM_STR); } $stmt->execute(); any ideas? Is it because the bindParam's need a unqiue name in their loop? Thanks
  8. Very sorry for the re-post, but does anyone have any suggestions here?
  9. Any suggestions anyone?
  10. hey all i have a facebook connect script which is working fine, and after the user logs in, it returns your facebook data (name, id etc) attached to this post is the script - which works great if anyone is looking for a good example Once the user has logged in, I want to run on a seperate page, a script which pulls data about a specific pages My question is, how much of the attached code can be removed once the user has logged in, i'd asume as the user is already logged in, there is a bunch of code which deals with the login processs which could be deleted or do i have to use the whole script when accessing anything on the graph?
  11. Hey all I'm working on a script which needs to connect to the Google Calendar API, but when I run the code I get Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error refreshing the OAuth2 token, message: '{ "error" : "invalid_grant" }'' in /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php:341 Stack trace: #0 /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php(300): Google_Auth_OAuth2->refreshTokenRequest(Array) #1 /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php(230): Google_Auth_OAuth2->refreshTokenWithAssertion() #2 /home/public_html/cal_test/google-api-php/src/Google/Service/Resource.php(171): Google_Auth_OAuth2->sign(Object(Google_Http_Request)) #3 /home/public_html/cal_test/google-api-php/src/Google/Service/Calendar.php(1133): Google_Service_Resource->call('list', Array, 'Google_Service_...') #4 /home/public_html/cal_test/index.php(34): Google_Service_Calendar_CalendarList_Resource->listCalendarList() #5 {main} thrown in /home/public_html/cal_test/google-api-php/src/Google/Auth/OAuth2.php on line 341 The code i'm using is <?php error_reporting(-1); ini_set('display_errors', 'On'); require_once "google-api-php/src/Google/Client.php"; require_once "google-api-php/src/Google/Service/Calendar.php"; // Service Account info $client_id = 'CLIENT_ID'; $service_account_name = 'EMAIL'; $key_file_location = 'FILE_LOC'; // Calendar id $calName = 'CAL_ID'; $client = new Google_Client(); $client->setApplicationName("Calendar test"); $service = new Google_Service_Calendar($client); $key = file_get_contents($key_file_location); $cred = new Google_Auth_AssertionCredentials( $service_account_name, array('https://www.googleapis.com/auth/calendar.readonly'), $key ); $client->setAssertionCredentials($cred); $cals = $service->calendarList->listCalendarList(); //print_r($cals); //exit; $events = $service->events->listEvents($calName); foreach ($events->getItems() as $event) { echo $event->getSummary(); } ?> i've spent serveral hours trying to locate a fix on Google, but so far i'm stuggling Can anyone help me? Thanks
  12. Hi I have the following code, which works fine. How can I pull in any images attached to the email and display them under the echo $val ? Thanks $mbox = imap_open("{SERVER}", "user", "pass"); echo "<h1>Mailboxes</h1>\n"; $folders = imap_listmailbox($mbox, "{SERVER}", "*"); if ($folders == false) { echo "Call failed<br />\n"; } else { foreach ($folders as $val) { echo $val . "<br />\n"; } } echo "<h1>INBOX</h1>\n"; $headers = imap_headers($mbox); if ($headers == false) { echo "Call failed<br />\n"; } else { $i=0; foreach ($headers as $val) { $i++; echo $val . "<br />\n"; } } imap_close($mbox);
  13. thanks, i'll give that a try So are you disabling ATTR_EMULATE_PREPARES by using PDO::ATTR_EMULATE_PREPARES => false and what's the reason for doing so?
  14. Ok, so is this a logical way of doing it $array=array(24,27); $i=0; foreach($array as $val) { if($i > 0) { $query_in .= ','; } $query_in .= ':'.$i; $i++; } and in the query use `id` IN ('.$query_in.') and finish off with $i=0; foreach($array as $val) { $sth->bindParam(':'.$i, $array[$i]); $i++; } which seems to output a result, but i'm not sure if this is the best way to do it thanks
  15. Great thanks. I am going to start using PDO. I managed to get this working $type=1; $sth = $dbh->prepare('SELECT `name`,`id` FROM `people` WHERE `type` = :type'); $sth->bindParam(':type', $type); but if I use $type=1; $ids=array(24,25,26,27,28,29,30); $sth = $dbh->prepare('SELECT `name`,`id` FROM `people` WHERE `type` = :type AND `id` IN (:ids)'); $sth->bindParam(':type', $type); $sth->bindParam(':ids', $ids); then I get "Notice: Array to string conversion". I've looked around to see how best to convert $ids=array(24,25,26,27,28,29,30); but cannot seem to find the answer anywhere what am i doing wrong? thanks
  16. Just out of curiosity, would you suggest that PDO would be better all round? Or just for specific parts of a site? What's the benefit of PDO over MySQLi
  17. thanks man, i'll give that a go
  18. The top part of the code looks like $arrays = array(1,2,4,7,9); //for the array values as comma separated $build_array = implode(',', $arrays); //for the SQL query $build_in = implode(',', array_fill(0, count($arrays), '?')); //for the bind_param string $build_bind_param .= 's'; foreach($arrays as $array) { $build_bind_param .= 's'; } $build_bind_param .= 'ii'; $stmt = $mysqli->prepare("SELECT d.id,d.val FROM datalog pd LEFT JOIN datafeeds d ON d.id = pd.did WHERE pd.pid = ? AND pd.aa = ? AND pd.bb = ? AND d.type IN ($build_in)"); $stmt->bind_param($build_bind_param, $id,$aa=1,$bb=1,$build_array); $stmt->execute(); and I get; Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables is this not the correct way to do it? thanks
  19. Hi I tried dynamically creating the bind_parm, but I couldnt get it working. Is it possible you could show an example of building up the bind_parm? I've been told that PDO is not possible with the server setup i've got thanks
  20. Hi I wonder if someone may help, I have already had a good look online, but not found a solution that works with what i'm trying to do At the moment I have the following code and it works great $stmt = $mysqli->prepare("SELECT d.id,d.val FROM datalog pd LEFT JOIN datafeeds d ON d.id = pd.did WHERE pd.pid = ? AND pd.aa = ? AND pd.bb = ?"); $stmt->bind_param('sii', $id,$aa=1,$bb=1); $stmt->execute(); $stmt->bind_result($id,$val); mysqli_stmt_store_result($stmt); if(mysqli_stmt_num_rows($stmt) != 0) { while ($stmt->fetch()) { $array[] = array('numA'=>$id, 'numB'=>$val); } } return $array; but what I would like to do is use an array, which could be any length $array = array(1,2,4,7,9); and change my query to include d.type IN ($array) could someone give me some help? thanks
  21. Hi all I have the following in my .htaccess file RewriteRule ^([^/]+)/ /$1.php?q=$1 [L,QSA] and this is great because any PHP page I create, such as 'about.php' can be rewritten as '/about/' - so that is all good. the problem is, I also want to let users create their own custom URL's for their profiles in the root of the site, such as '/david-jones/' but because 'david-jones' is not actually a real PHP page (but rather a database entry), I cant use a rewrite rule as far as I can see. Would the best solution be to piggy back the error 404 rewrite rule, so that if an actual PHP page isn't found, it takes them to the 404 error page which actually contains a script to lookup the users details, if the user details are not found, i'd show a "the page cannot be found" message. Or is there a more elegant way to do this? Thanks
  22. Hi I want to get my <footer> to appear at the bottom of my page, but I dont want it to be fixed there. So if the middle contents of a page is very short, the <footer> will be visibled at the bottom of the browser, but if the page contents is long, then the <footer> would just disappear at the bottom of the contents. Can this be done? Thanks
  23. Hi I have this json file {"user":"RD32","time":"14:00","type":"staff"} {"user":"XC12","time":"21:00","type":"management"} {"user":"YG89","time":"09:00","type":"staff"} and I want to pull just "staff" from it and output like user: RD32 time: 14:00 ----- user: YG89 time: 09:00 is that possible?
  24. Hello I'm using the following prepared statement code $member_id = 43; $lession = array("AA,BB,CC"); $lessions = "'".implode("','",$lession)."'"; $prep_stmt = "SELECT COUNT(da.points) as points, da.user FROM data da WHERE da.memberid = ? AND da.lession IN (?) GROUP BY da.memberid LIMIT 1"; $stmt = $database->prepare($prep_stmt); $stmt->bind_param('ss', $member_id,$lessions); for some reason its not working. annoyingly, if I change it to $member_id = 43; $prep_stmt = "SELECT COUNT(da.points) as points, da.user FROM data da WHERE da.memberid = ? AND da.lession IN ('AA') GROUP BY da.memberid LIMIT 1"; $stmt = $database->prepare($prep_stmt); $stmt->bind_param('s', $member_id); then it works fine so i have figured its to do with the array im passing to da.lession IN (?) any idea how i can fix this so it works off my array $lession = array("AA,BB,CC"); thanks
  25. sorry, I just saw this and it works, thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.