smallseo.info

facebook-php-sdk

This SDK is deprecated. Find the new SDK here: <a href="https://github.com/facebook/facebook-php-sdk-v4">https://github.com/facebook/facebook-php-sdk-v4</a>

When skipping Facebook authentication, shouldn't I get back an appropriate value to indicate the users decision?

In my app, I have the following code:

$loginUrl = $facebook->getLoginUrl( array( 'scope' => 'publish_stream' ) );
header("Location: ".$loginUrl);

which takes the user to facebook and asks them:

'[oshirowanens app] would also like permission to:
Post on your behalf
This app may post on your behalf, including status updates, photos and more.
Allow - Skip

If I click Skip, I am redirected back to my app, where I would expect to see the following url parameteres error, error_reason, and error_description similar to what happens when I user fails to login into their facebook account?

(optional) The URL to redirect the user to once the login/authorization process is complete. The user will be redirected to the URL on both login success and failure, so you must check the error parameters in the URL as described in the authentication documentation. If this property is not specified, the user will be redirected to the current URL (i.e. the URL of the page where this method was called, typically the current URL in the user's browser).

Source: https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl/

Does something like that exist for skipping a permissions authentication request like the publish_stream?


Source: (StackOverflow)

Unknown algorithm. Expected HMAC-SHA256 spam in logs

I'm using facebook php sdk 3.1.1 and the current version of the facebook JS sdk. Our users are not reporting errors, but I'm seeing a ton of error log messages like this:

Unknown algorithm. Expected HMAC-SHA256

I see from the source that the error is triggered when reading a signed request with the wrong encoding encoding algorithm, but I'm not sure why that would be, as all signed requests should be generated by the facebook JS code.

Anyone seen this behavior? Any idea how bad a thing this is, or whether it's really indicative of errors? I have been unable to replicate it on demand.


Source: (StackOverflow)

suddenly, getUser became to return 0.(PHP 3.1.1 SDK)

Only 10 hours ago, if I call $facebook->getUser(), I can get the correct user_id, but now, it always returns 0. Of cource, I have not changed my code.

There is another strange point.

redirect_url contains:

?sate=9b1772342342...&code=9b177asd2l..&base_domain=9b1772.3423#=

I can't release the site.. Please help!


Source: (StackOverflow)

How to login with OFFLINE_ACCESS using the new Facebook PHP SDK 3.0.0?

with the old (2.x) SDK I used this to log someone with offline_access:

$session = array
(
    'uid' => $userdata['fb_uid'],
    'sig' => $userdata['fb_sig'],
    'access_token' => $userdata['fb_access_token']
);

$facebook->setSession($session);

In the new SDK this function doesnt exist anymore. I think I need to login using:

setPersistentData($key, $value)

but this function is protected and I dont know what 'code' is? Do I need this to log the user in or not? And what's going on with 'sig'? Don't I need this anymore?

Hope someone already figured this out because the documentation really doesn't help!


Source: (StackOverflow)

Facebook PHP API post to wall falls under "Recent Posts by Others"

I want to post a message to the wall of a Facebook Page. I am the admin of the app and the page used in this code, I already gave permissions needed for my app to be able to post on my page, it works when I use only the field "message", like this:

$message = array(
            'message' => "Test2",<br>
           );
$result = $fb->api('/411895472189524/feed','POST',$message);

The code above posts to my page wall and the post is made "from" the page itself, just like if I would do it manually from facebook. This is working great.

But when I try to add more fields like "link" or "picture" or "description" the post goes in the "Recent Posts by Others on TEST Jojo Page" and the post is now made from my personnal account (Joelle Landrie) instead of from the page itself. See code below.

$message = array(
            'message' => "Test2",
            'picture' => "http://www.cleanpopo.com/uploads/1/3/1/5/13154615/245431315.jpg",
            'description' => "This is a test description",
            'link' => "google.com"
           );
$result = $fb->api('/411895472189524/feed','POST',$message);

See: https://www.facebook.com/pages/TEST-Jojo-Page/411895472189524

The link field seems to be causing problem, I can get a successful post on my page using the message, picture and description field. Only this is useless to me, I need my post to have a link.



SOLUTION

Thanks to Shadowfax who asked if I was using the "page_access_token". I was not. I started looking on the web how to get this token, added it to my code and now it works great!!

The Final Code

$appId = 'YOUR APP ID';
$secret = 'YOUR SECRET';
$returnurl = 'http://www.yoursite.com';
$permissions = 'manage_pages, publish_stream, offline_access';

$fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret));
$fbuser = $fb->getUser();

if($fbuser){

        $page_id = "YOUR PAGE ID";
        $page_access_token = "";
        $result =  $fb->api("/me/accounts");

        // loop trough all your pages and find the right one
        if( !empty($result['data']) )
        {
           foreach($result["data"] as $page) 
           {
             if($page["id"] == $page_id)
             {
               $page_access_token = $page["access_token"];
               break;
             }
           }
        }
        else
        {
          echo "AN ERROR OCCURED: could not get the access_token. Please verify the page ID ".$page_id." exists.";
        }

        // set the facebook active facebook access token as the one we just fetch
        $fb->setAccessToken($page_access_token);

        // Now try to post on page's wall
        try{
            $message = array(
                'message' => "YOUR MESSAGE",
                'picture' => "YOUR PICTURE",
                'description' => "YOUR DESCRIPTION",
                'link' => "YOUR LINK"
            );
            $result = $fb->api('/'.$page_id.'/feed','POST',$message);
            if($result){
                echo 'Successfully posted to Facebook Wall...';
            }
        }catch(FacebookApiException $e){
            echo $e->getMessage();
        }

    }else{

        $fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions));
        echo '<a rel='nofollow' href="'.$fbloginurl.'">Login with Facebook</a>';

    }

Source: (StackOverflow)

I upgraded to FQL to Graph API - am I using it correctly?

I used the FQL until a few days ago to retrieve Facebook data, but I noticed that it will be discontinued in about 1 year so I upgraded to Graph API. But am I using it correctly? Will this method work still next year? I am still using a

facebook.php, base_facebook.php and fb_ca_chain_bundle.crt

from 2011 but then again I only need these functions.

Here's my code, thanks for any advice you can give me :)

        function get_content($URL){
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                  curl_setopt($ch, CURLOPT_URL, $URL);
                  $data = curl_exec($ch);
                  curl_close($ch);
                  return $data;
        }

        $access_token =  $facebook->getAccessToken();

        $data = get_content("https://graph.facebook.com/" . $facebook_id . "/?fields=name,first_name,last_name,email&access_token=".$access_token);
        $data_array = json_decode($data, true);

        $new_array = array(
            "uid" => $data_array['id'],
            "name" => $data_array['name'],
            "first_name" => $data_array['first_name'],
            "last_name" => $data_array['last_name'],
            "email" => $data_array['email']
        );

Source: (StackOverflow)

CurlException: 28: connect() timed out?

Today I was trying to make application on Facebook using PHPSDK and I saw ocassionaly displayed exception from library saying CurlException: 28: connect() timed out!

So, to check if it's my code bug I downloaded latest library PHPSDK from github. Then I was trying to run examples/example.php file few times, after that I look into error log and this error was also there (not always, looks like it's kind of random thing).

I was trying to find solution on developer forum without any success, as I notice this kind of problem occur in the past, and none knows why.

Any solutions?

Thanks


Source: (StackOverflow)

Facebook OAuth Error: Application request limit reached

I'm trying to get facebook's example page working (again) which you can find here. I'm getting the following error:

Fatal error: Uncaught OAuthException: (#4) Application request limit reached thrown in C:\wamp\www\base_facebook.php on line 988

I've googled this and the problem seems to be easily fixed by using the steps outlined here. However, when I go to facebook.com/insights, my application isn't listed (I am logged in).

The weirder part is that when I go to my app via Developers > My apps, I can go to the page of my app and click "Insights". This brings me to the Insights page for my app... but the diagnostic section is nowhere to be found. Can anyone help?


Source: (StackOverflow)

Facebook (FB.login) not requesting my permissions

so after updating to the php 3.0 sdk and what not, my FB.login() function no longer asks for the permissions I set it to ask. Any one else getting this? Here's some code for you:

window.fbAsyncInit = function() {
  FB.init({
    appId: 'xxx',
    status: true,
    cookie: true,
    xfbml: true,
    oauth : true // enables OAuth 2.0
  });
  // whenever the user logs in, we refresh the page
  //FB.Event.subscribe('auth.login', function() {
  //  window.location.reload();
  //});      
};


FB.login(function(response) {
  if (response.authResponse) {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
      console.log('Good to see you, ' + response.name + '.');
      FB.logout(function(response) {
        console.log('Logged out.');
      });
    });
  } else {
    console.log('User cancelled login or did not fully authorize.');
  }
}, {scope:'read_stream,publish_stream,offline_access'});

The way I'm trying to access it, is through an onClick="FB.login();". Can anyone help?


Source: (StackOverflow)

Graph API new feed post object-Attachment not showing

I'm having a strange problem with the graph API, the below code used to work for me adding a post to a users news feed with a thumbnail of the attached photo (referenced in 'object_attachement' parameter).

However now the post is created as expected however the thumbnail is empty. The photo_id I am using exists in the user's photo collection.

Results of below code now.

    $photo_ID = "3415678920211";//Valid Facebook Photo ID...        
    $facebook = new Facebook($config);

    $attachment =  array(
            'access_token' => $user_token,
            'message' => "Test Message",
            'caption' => "THis is a Caption",
            'name' => "Test Name",
            'description' => "This is a description",
            'link' => 'http://url.com/',
            'object_attachment' => $photo_id,
    );

    $response = $facebook->api("/".$userID."/feed/", 'POST', $attachment);

Am I doing something wrong? I am sure this did use to work and wonder if something changed in the API underneath me.

[Update] I noticed that this seems to happen when I specify both link & object_attachment in the same POST. If I remove the link param from the above then I get a slightly better update however this isn't great as the main reason I want this post to exist is for the addition of the link.


Source: (StackOverflow)

Reading data from Facebook graphObject

A user has accepted my Facebook app. I can now access some of their data. It is returned as a graphObject, which contains something like:

Facebook\GraphObject Object ( [backingData:protected] => Array ( [id] => 11111 [first_name] => Bob [gender] => male [last_name] => Builder [link] => https://www.facebook.com/app_scoped_user_id/11111/ [locale] => de_DE [name] => Bob Builder [timezone] => 2 [updated_time] => 2014-02-14T14:35:54+0000 [verified] => 1 ) )

Unfortunately I cannot get at the data inside this object. Reading it like an array throws an error:

$fbid = $graphObject['id']; // Cannot use object of type Facebook\GraphObject as array
$fbid = $graphObject->id; //  Undefined property: Facebook\GraphObject::$id

How can I get at the ID?


Source: (StackOverflow)

How to extract Facebook Access token Expiration Info

is there ay way to get the Expiration date of the access token, I need this so I can refresh my session, also I want this way so I can avoid to look up on facebook user data when being fetch via PHP cURL.

also on this link https://developers.facebook.com/tools/access_token/ if I click the DEBUG button in one of my custom app, I can see this info (for example)

App ID: 23131XX0000123 : My Custom App
User ID: XX99858XX : Mario Bro
Issued: XX11111XX : 2:00 pm Feb 10 2012
Expires: XX11111XX : 3:00 pm Feb 10 2012
Valid:  True
Origin: Unknown
Scopes: email user_likes

and it display the expiration date from that app. Is there a way I can get that info in PHP SDK or in a graph URL command?


Source: (StackOverflow)

Why is getSessionFromRedirect() return a NULL?

I have the following code which redirects the user to log into facebook and tries to retrieve the session but the session is NULL:

<?php

session_start();

require 'vendor/autoload.php';

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;

FacebookSession::setDefaultApplication('Foo', 'Bar');

$helper = new FacebookRedirectLoginHelper('Baz');
$loginUrl = $helper->getLoginUrl();  

echo '<a rel='nofollow' href="' . $loginUrl . '">Log In</a>';  

$session = $helper->getSessionFromRedirect();  

// This displays [NULL] always
echo '[' . gettype($session) . ']';

?>

I don't understand why the $session is always NULL. Please help.


Source: (StackOverflow)

Fatal error: Uncaught CurlException: 7: couldn't connect to host thrown in ....src/base_facebook.php on line 887

I'm trying to develop a sample facebook php login example following the example here

I've hosted my app here, but I'm getting the error message in the question whenever I try to access the link. Here's the code segment that throws the error

try {
  $e = new FacebookApiException(array(// LINE 887
             'error_code' => curl_errno($ch),
             'error' => array(
             'message' => curl_error($ch),
             'type' => 'CurlException',
        ),
  ));
  curl_close($ch);
}

// edit suggested by Kneel-before ZOD
catch(FacebookApiException $e) {
  $result = $e->getResult();
  echo 'Got an : ', $e->getType(),' while posting';
  echo(json_encode($result));
}

catch(Exception $e){
  echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Im quite sure Ive setup the APP ID and secret correctly in index.php.

Here's a screenshot of my app setup on facebookApp setup

Any help would be appreciated. Thanks!


Source: (StackOverflow)

Facebook getUser() function returning user ID after logout

I'm developing using the Facebook PHP SDK.

I wanted to make it so that when the user logs out of Facebook, they will automatically be logged out of my website too.

I am using the following code to detect the session, using the session cookie:

$facebook->getUser();

For some reason, the getUser() function still returns the user's Facebook ID, even after they have logged out of Facebook on their website.

Am I to detect the session first using another Function?

On the official documentation example here, is the following excerpt from their comments:

// Get User ID
$user = $facebook->getUser();

// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.

This lead me to believe that the session cookie for Facebook would become unset upon Facebook logout?

Kind Regards,

Luke


Source: (StackOverflow)