Jump to content

dweb

Members
  • Posts

    122
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

dweb's Achievements

Member

Member (2/5)

0

Reputation

  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. 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?
  10. 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
  11. 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);
  12. 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?
  13. 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
  14. 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
×
×
  • 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.