Error 102 when connect to FB API - php

I am seeing this error message when I connect to fb
Fatal error: Uncaught Exception: 102:
parameters uid or session key required thrown in C:\Online\lib\fb\base_facebook.php
on line 708
May I know what is the problem? I have verified the appID and Secret Key too. Thank you.
Here is my code in php
$facebook = new Facebook(array('appId' => FB_ID, 'secret' => FB_SCRT, 'cookie' => true,));
$user = $facebook->getUser();
$api_call = array(
'method' => 'users.hasAppPermission',
'uid' => $user,
'ext_perm' => 'publish_stream'
);
$users_hasapppermission = $facebook->api($api_call);
I am trying to have the user's permission to publish to FB stream

Related

Facebook PHP SDK V3 login token - Fatal error: Uncaught OAuthException:

The code below works fine with the PHP SDK v3. However, I had to use a java sdk login at first and now I don't know how to get a token with PHP or check if the user is logged in or not with PHP. I GET THE ERROR BELOW.
I can not use the SDK 4 yet as my hosting will not allow it. Long story. I have tried SEVERAL sites and tutorials for the past few hours to no avail. Can someone show me a simple way to do this? With code examples? What do I need to change the canvas url to on the Facebook app? etc..
Here is an error I get without the login.
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in
require 'Facebook3/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'myID',
'secret' => 'MySecret',
));
$attachment = array(
'message' => 'COOL',
'name' => 'Some Info',
'caption' => "more info",
'link' => 'http://aLink.com',
'description' => 'View Trailer Here!',
'picture' => 'http://Picture.com/images/aPic.png',
'actions' => array(
array(
'name' => 'Get Search',
'link' => 'http://www.google.com',
)
)
);
$result = $facebook->api('/me/feed/', 'post', $attachment);

Facebook server login auth issue.

I'm trying to simply post to a facebook page as the page.
I created an app, set permissions ( manage_pages ), and requested an app token ( via https://developers.facebook.com/docs/facebook-login/access-tokens/ ).
I think I'm almost there but I'm getting an "PHP Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action" error.
<?php
require_once('facebook.php');
$config = array();
$config['appId'] = 'xxxxxxxxxxxxx';
$config['secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$config['fileUpload'] = false; // optional
$facebook = new facebook($config);
$access_token = "app token I got from link above";
$facebook->setAccessToken($access_token);
$page_id = "xxxxxxxxxxxxxxxx";
$args = array(
'access_token' => $access_token,
'message' => "This is just a test.",
'name' => "Just a test.",
'link' => "http://www.xxxx.com/",
'picture' => "http://www.xxxx.com/Logo.jpg",
'actions' => array(
'name' => 'See Pic',
'link' => "http://www.xxxx.com/Logo.jpg"
)
);
$post = $facebook->api("/$page_id/feed","post",$args);
Where am I missing to give auth so I can post to the page? I've been over the settings under my app dashboard and don't see that I'm missing anything.
Thanks

Facebook Graph Api - Posting to page without logging

I'm trying to create a script that post status updates on facebook pages without logging-in the user. I've got access_token for my application and for the pages as the user granted the application once; but I always get the error
Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action
despite I've granted manage_pages and publish_stream permission.
Also if I use the access_token for the page I get the error
Fatal error: Uncaught OAuthException: Error validating access token: The session is invalid because the user logged out.
Here is the code I use.
$facebook = new Facebook(array(
'appId' => 'XXX',
'secret' => 'XXXXXXXXXXX'
));
$post = array(
'message' => 'Message to user'/*,
access_token = "XXXXXXXX"*/
);
$feed = '/[PAGE_ID]/feed';
$post_id = $facebook->api($feed, "post", $post);
Thanks.
Edit :
I finally managed to post status updates on a user's page while this user was disconnected, I had to generate the access_token through the server-side auth method.
Below is a small code smaple on how to do a FB post to a page:
yOU NEED:
Your_authToken_for_User
List item
saved_fb_Page_Token
$facebook = $facebook = new Facebook(array(
'appId' => $fbAppId,
'secret' => $fbAppSecret,
'cookie' => true,
));
$facebook->setAccessToken("Your_authToken_for_User");
//Now your FB instance is authenticated.
$pages= $facebook->api('/me/accounts'); //use the current authenticated FB instance to grab Pages. If you already know your page ID , skip this.
//Assuming you have a pageid in $page_id,(the $page_id can be grabbed from the $pages array).
$attachment = array(
'access_token' => $saved_fb_Page_Token,
'message' => "foo",
'name' => "Bar",
'link' => "http://foo.bar",
'description' => "barfoo",
'picture' => "an image url here",
);
$facebook->api('/' . $page_id . '/feed', 'POST', $attachment);//post to fb page

Facebook authorization looping / Error validating verification code

I have the follow code to login with Facebook:
// Include Facebook SDK
$this->facebook = new Facebook(array(
'appId' => 'APP ID',
'secret' => 'APP SECRET',
'cookie' => true
));
$uid = $this->facebook->getUser();
if($uid) {
try {
echo 'Done!';
} catch (FacebookApiException $e) {
echo $e;
error_log($e);
}
} else {
$loginUrl = $this->facebook->getLoginUrl(array(
'redirect_uri' => 'http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook',
'scope' => 'user_birthday'
));
echo('<script>top.location.href = "' . $loginUrl . '";</script>');
}
UPDATE 1
I can authorize the App, but, after authorization, I can't get the logged user, EVER redirecting to
http://ogabrielsantos.com.br/dev/index.php?route=account%2Fconnect%2Ffacebook&state=RANDOM STATE&code=RANDOM CODE#_=_
I have tried:
Put the APP in a server;
Verify APP settings. All is correct;
Verify if url is the same at settings and code. All is ok;
My url is properly written: http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook;
Reset APP SECRET.
Nothing worked.
You can check what happens going to:
http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook
Facebook ask you to authorize the app to get your website, which is a safe information.
UPDATE 2
The follow code:
$this->facebook = new Facebook(array(
'appId' => $this->connect->config->get('facebook_api_key'),
'secret' => $this->connect->config->get('facebook_app_secret'),
'cookie' => true
));
$uid = $this->facebook->getUser();
echo'<pre>';
print_r($this->facebook);
echo'</pre>';
exit;
returns:
Facebook Object
(
[sharedSessionID:protected] =>
[appId:protected] => APP ID
[appSecret:protected] => APP SECRET
[user:protected] => 0
[signedRequest:protected] =>
[state:protected] =>
[accessToken:protected] => APP ID|APP SECRET
[fileUploadSupport:protected] =>
[trustForwarded:protected] =>
)
I think the accessToken is wrong, returning my APP ID and SECRET with a pipeline separator.
UPDATE 3:
Now, I verify the code, but, always get Fatal error: Uncaught OAuthException: Error validating verification code
if(isset($_GET['code'])) {
$api = $this->facebook->api('/oauth/access_token', array(
'client_id' => APP ID,
'redirect_uri' => 'http://ogabrielsantos.com.br/dev/index.php?route=account/connect/facebook',
'client_secret' => APP SECRET,
'code' => $_GET['code']
));
echo'<pre>';
var_dump($api);
print_r($this->facebook->getUser());
echo'</pre>';
exit;
}
I have read some questions, which is similar but can't help-me.
Are you working on localhost? if yes it probably is the reason why.
If not, check your app settings in developers.facebook.com/apps/APP_ID
1. You have to compare the urls written in your code with the ones you have in your app settings.
2. Another reason could be the that the urls in you app settings are not properly written, I remember having to add index.php at the end of my urls in Page Tab settings. Worked for me
3. Another option is to get a new APP_SECRET and update your code
These options are from my personal experience, you issue could also be something else but you lose nothing trying
The Facebook Sharing and Facebook Sign In functions are completely separate and each require their own app.
Are you using facebook sharing in the page you want the login working on?
Ref: http://www.ning.com/help/?p=8523

Working with Facebook PHP SDK: Uncaught CurlException: 26: failed creating formpost dat

I had a look at several stackoverflow posts about this error message, but none of them worked for me.
I want to upload a photo to facebook:
public function uploadPhoto($path){
$photoSettings = array(
'access_token'=> $this->facebook->getAccessToken(),
'name' => 'uploaded foto',
'source' => '#' . realpath($path)
);
$photo = $this->facebook->api('me/photos','POST',$photoSettings);
}
When i call this function, i get the following error message:
Uncaught CurlException: 26: failed creating formpost data
I am 100% sure that the image i want to upload exists (and the path is correct).
This is my facebook initialization: (fileUpload is true)
$this->facebook = new Facebook(array(
'appId' => $this->config['appId'],
'secret' => $this->config['appSecret'],
'fileUpload' => true,
'cookie' => true
));
I really don't understand why i get that error because my code seems to be correct. Do you think there could be a problem with my server / the server's cURL configuration? I dont know much about cURL.
I hope you can help me! I am looking forward for your answers :-)
Greetings,
Andreas
Your realpath($path) is not pointing to the actual server image location. If $path is the complete path of the image, then use 'source' => '#' . $path instead.
I kept getting “CurlException: 26: failed creating formpost data”
Here is my working code for uploading a photo from the same directory as the PHP page communicating with Facebook:
$facebook = new Facebook(array(
'appId' =>'*****',
'secret' =>'*******',
'fileUpload' => true,
'cookie' => true
));
$user = $facebook ->getUser();
if($user)
{
$facebook->setFileUploadSupport(true);
$args = array(
'message' => 'TEst from App.',
'image' => '#' . realpath('awesome.jpeg')
);
try {
$data = $facebook->api('/me/photos', 'post', $args);
} catch(FacebookApiException $e) {
echo "ERROR: " . $e;
}
}

Categories