Facebook login

    ICTscripters maakt gebruik van cookies. Door het gebruiken en browsen naar onze site gaat je automatisch akkoord met het gebruik van cookies. Klik hier voor meer informatie

    • Facebook login

      Wie kan mij helpen met het Facebook login op een website?
      Ik heb een website waar je altijd via Facebook kon inloggen, dit heeft altijd gewerkt maar blijkt op versie 2.2 te zijn gemaakt.
      Inmiddels zitten ze op versie 3.2 en nu werkt het niet meer en krijg het ook niet werkend momenteel.

      Wie heeft er zin en tijd om mee te denken zodat het weer werkt.

      Dit is de fout wat die nu aangeeft:
      Graph returned an error: (#100) Invalid edge (access_token) on node type (Page)

      PHP Source Code: facebooklogin.php

      1. <?php
      2. session_start();
      3. error_reporting(0);
      4. //already logged in?
      5. if ($_SESSION["valid_een"] && $_SESSION["valid_twee"] && !isset($_GET["logout"])) {
      6. include_once("../includes/db_connect.php");
      7. $url = WEBSITE_URL."/members/";
      8. header("Location: $url");
      9. exit;
      10. }
      11. include_once("../includes/functions.php");
      12. require(WEBSITE_DIR.'/includes/Facebook/autoload.php');
      13. $fb = new Facebook\Facebook([
      14. 'app_id' => $FB_APPCODE,
      15. 'app_secret' => $FB_SECTRET,
      16. 'default_graph_version' => 'v2.2',
      17. ]);
      18. $helper = $fb->getRedirectLoginHelper();
      19. $permissions = ['email']; // Optional permissions
      20. $loginUrl = $helper->getLoginUrl(WEBSITE_URL.'/members/fb-callback.php', $permissions);
      21. header("Location: $loginUrl");
      22. ?>
      Laat alles zien

      PHP Source Code: fb-callback.php

      1. <?php
      2. session_start();
      3. error_reporting(0);
      4. //already logged in?
      5. if ($_SESSION["valid_een"] && $_SESSION["valid_twee"] && !isset($_GET["logout"])) {
      6. include_once("../includes/db_connect.php");
      7. $url = WEBSITE_URL."/members/";
      8. header("Location: $url");
      9. exit;
      10. }
      11. include_once("../includes/functions.php");
      12. require(WEBSITE_DIR.'/includes/Facebook/autoload.php');
      13. $fb = new Facebook\Facebook([
      14. 'app_id' => $FB_APPCODE,
      15. 'app_secret' => $FB_SECTRET,
      16. 'default_graph_version' => 'v2.2',
      17. ]);
      18. $helper = $fb->getRedirectLoginHelper();
      19. try {
      20. $accessToken = $helper->getAccessToken();
      21. } catch(Facebook\Exceptions\FacebookResponseException $e) {
      22. // When Graph returns an error
      23. echo 'Graph returned an error: ' . $e->getMessage();
      24. exit;
      25. } catch(Facebook\Exceptions\FacebookSDKException $e) {
      26. // When validation fails or other local issues
      27. echo 'Facebook SDK returned an error: ' . $e->getMessage();
      28. exit;
      29. }
      30. if (isset($accessToken)) {
      31. $fb->setDefaultAccessToken($accessToken);
      32. try {
      33. $response = $fb->get('/me?fields=id,name,email');
      34. $user = $response->getGraphUser();
      35. } catch(Facebook\Exceptions\FacebookResponseException $e) {
      36. // When Graph returns an error
      37. echo 'Graph returned an error: ' . $e->getMessage();
      38. exit;
      39. } catch(Facebook\Exceptions\FacebookSDKException $e) {
      40. // When validation fails or other local issues
      41. echo 'Facebook SDK returned an error: ' . $e->getMessage();
      42. exit;
      43. }
      44. }
      45. $user = $response->getGraphUser();
      46. //client data from FB
      47. $fb_client_id = $user['id'];
      48. $fb_client_name = $user['name'];
      49. $fb_client_email = $user['email'];
      50. //check if user exists in our database check on facebook id or email
      51. // email exists, but no facebook id? update profile with facebook id
      52. $fb_result = q ("select
      53. wgid,emailmd,wachtwoordmd,valid
      54. from members where
      55. email = '$fb_client_email' AND facebookid = ''
      56. limit 1");
      57. //yes, member exists, login
      58. if ($fb_result->num_rows>0){
      59. $row_fb = $fb_result->fetch_assoc();
      60. $local_client_id = $row_fb["wgid"];
      61. //update profile with facebook id
      62. $sql_insert = q("update members set
      63. facebookid = '$fb_client_id'
      64. where wgid = '$local_client_id'
      65. LIMIT 1");
      66. }
      67. //check if facebook id is member
      68. $fb_result = q ("select
      69. wgid,emailmd,wachtwoordmd,valid
      70. from members where
      71. email = '$fb_client_email' AND facebookid = '$fb_client_id'
      72. limit 1");
      73. //yes, member exists, login
      74. if ($fb_result->num_rows>0){
      75. $row_fb = $fb_result->fetch_assoc();
      76. //user with this email is blocked by admin
      77. if($row_fb["valid"]==0){
      78. $logoutUrl = $facebook->getLogoutUrl(array( 'next' => WEBSITE_URL.'/members/login.php?blockeduser=1'));
      79. header("Location: $logoutUrl");
      80. exit;
      81. }
      82. $latste_inlog = time();
      83. $inlog_update = "update members
      84. set laatsteinlog = '$latste_inlog', xingelogd=xingelogd+1
      85. where facebookid = '$fb_client_id'
      86. LIMIT 1";
      87. $inlog_update = q($inlog_update);
      88. $_SESSION["valid_wgid"] = $row_fb["wgid"];
      89. $_SESSION["valid_een"] = $row_fb["emailmd"];
      90. $_SESSION["valid_twee"] = $row_fb["wachtwoordmd"]; //sha1($wachtwoord);
      91. if(isset($_SESSION["doost"])) {
      92. $urlto = StripDanger($_SESSION["doost"]);
      93. unset($_SESSION["doost"]);
      94. header("Location: ".$urlto);
      95. }else
      96. header("Location: ".WEBSITE_URL."/members/?viafb");
      97. exit;
      98. }
      99. //no? create new profile
      100. else{
      101. //we did not get email from facebook, or user denied
      102. if(empty($fb_client_email)){
      103. header("Location: ".WEBSITE_URL."/members/register.php?set=1&facebook=false");
      104. exit;
      105. }
      106. //no, member here for the first time
      107. // No errors, so save to DB
      108. $time = time();
      109. $valid = generatePassword(20);
      110. $emailmd = sha1(STD_WN_MAIL.$fb_client_email);
      111. $validto = time(); //prob never used, but just to be sure.
      112. //create pass for customer wich will be send to him via email
      113. $wachtwoord = generatePassword(6);
      114. $wachtwoordmd = sha1(STD_WN_PASS.$wachtwoord);
      115. //from fb
      116. $contact = StripDanger($fb_client_name);
      117. if(empty($username))
      118. $username = $contact;
      119. //if(STD_CREDITS==999)
      120. $newcredits = '0';
      121. //else $newcredits = STD_CREDITS;
      122. //put it all in the DB
      123. $sql_insert = "insert into members
      124. (facebookid,email, emailmd, wachtwoordmd, bedrijf,username,bedrijfsnaam, contactpersoon,adres,postcode,
      125. woonplaats, glatti, glongg, telefoon, geslacht, website, lidsinds, credits, validto, verlengd, valid, receivemail)
      126. values
      127. ('$fb_client_id','$fb_client_email','$emailmd', '$wachtwoordmd', '0','$contact','','$contact','','',
      128. '', '', '', '', '1', '', '$time', '$newcredits', '$validto', '$time', '1','1')";
      129. $result = q($sql_insert);
      130. $klantenid = mysqli_insert_id($GLOBALS['db']);
      131. $_SESSION["valid_wgid"] = $klantenid;
      132. $_SESSION["valid_een"] = $emailmd;
      133. $_SESSION["valid_twee"] = $wachtwoordmd; //sha1($wachtwoord);
      134. //mail wachtwoord naar user:
      135. $message = formatString(LANG_COMP_REG_HELLO,array(str_replace('\\','',$contact))).', <br /><br />
      136. '.formatString(LANG_COMP_REG_WELCTA,array(ucfirst(STD_DOMEIN))).'<br /><br />
      137. '.LANG_COMP_REG_EMAD.': '.$fb_client_email.'<br />
      138. '.LANG_COMP_REG_PASS.': '.$wachtwoord.'<br />
      139. <br />
      140. '.LANG_COMP_REG_REAGARDS.',<br />
      141. <br />
      142. '.ucfirst(STD_DOMEIN).'<br />
      143. <br />
      144. <br />
      145. '.LANG_COMP_REG_THAUTOP;
      146. //echo $message; //debug test
      147. $subject = formatString(LANG_COMP_REG_SUBJECT,array(ucfirst(STD_DOMEIN))); //STD_DOMEIN;
      148. $x = send_mail(STD_EMAIL_WEB,STD_DOMEIN,$fb_client_email,$contact,$subject,$message);
      149. header("Location: ".WEBSITE_URL."/members/?welcomefb");
      150. exit;
      151. }
      152. exit;
      153. ?>
      Laat alles zien

      Post werd 1x aangepast, het laatst door roy59 ().