php - Uncaught OAuthException: Error validating application -
i developing first facebook app, includes creating new album , posting photos user wall. learning through facebook documentation , few tutorial , came code, getting following error it.
fatal error: uncaught oauthexception: error validating application. thrown in /home/base_facebook.php on line 1106
plus: don’t know if matters or not, when printing out the
echo $facebook->getuser();
variable giving me ‘0’ in return though user (which in case myself) logged in.
kindly me through this.
code:
$config = array( 'appid' => '3663250024856', 'secret' => 'b14ac6d2b7dbdtyb259599b06983e881', 'fileupload' => true, 'cookie' => true ); $facebook = new facebook($config); echo "user status:".$facebook->getuser(); $facebook -> setfileuploadsupport(true); $album_details = array('message' => 'album desc', 'name' => 'album name'); $create_album = $facebook -> api('/me/albums', 'post', $album_details); $album_uid = $create_album['id']; $photo_details = array('message' => 'photo message'); $file = "temp/".$imagename; $photo_details['image'] = '@' . realpath($file); $upload_photo = $facebook -> api('/' . $album_uid . '/photos', 'post', $photo_details);
even though user logged in, user needs give permission app before can make api calls.
basically flow user authentication using facebook php sdk should this:
detect whether user logged in , given permission app.
if hasn't given permission, redirect him login , application permission page. after logging in , giving permission, he'll redirected again application page.
otherwise, show content of app, make api calls,...
here modified sample code php sdk's documentation page handle authentication should work if modify appid, appsecret , redirect_uri:
<?php require_once 'fb_php_sdk/facebook.php'; $appid = 'your_app_id'; $appsecret = 'your_app_secret'; // create application instance (replace appid , secret). $facebook = new facebook( array( 'appid' => $appid, 'secret' => $appsecret, 'fileupload' => true, 'cookie' => true )); // user id $user = $facebook->getuser(); if ($user) { try { // proceed knowing have logged in user who's authenticated. $user_profile = $facebook->api('/me'); } catch (facebookapiexception $e) { error_log($e); $user = null; } } // login or logout url needed depending on current user state. if ($user) { $logouturl = $facebook->getlogouturl(); } else { $loginurl = $facebook->getloginurl( array( 'canvas' => 1, 'fbconnect' => 0, 'scope' => '',//these extended permissions need app, add/remove according requirement 'redirect_uri' => 'http://apps.facebook.com/test_app_azk/',//this redirect uri user redirected after allow, )); } if ($user) { //show content of app //make api calls var_dump($user_profile); } else { //redirect user loginurl echo "<script>parent.location = '".$loginurl."';</script>"; }
hope helps.
Comments
Post a Comment