Topic-icon How to call setFileUploadSupport

Active Subscriptions:

None
11 years 7 months ago #27160 by catedh
Hi Alex,

I want to write simple application that user who already loged in by JFB can click an image and post in their facebook album and tagged them.
I have trouble to call setFileUploadSupport through JFB instance. or there a way to call the function in other way?
Now I always get error:
Fatal Error: Call to undefined method JFBConnectFacebookLibrary::useFileUploadSupport()
May I get your suggest please? :)

Thank you Alex.

Heres my code now:
set_time_limit(50);
require_once JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php'; 
$fbClient = JFBConnectFacebookLibrary::getInstance();
// Get User ID
$user = $fbClient->getUserID();
if ($user) {

} else {
    $loginUrl = $fbClient->getLoginUrl();
    header('Location:' . $loginUrl . '&scope=user_photos,publish_stream');
}
// Login or logout url will be needed depending on current user state.
        if ($user) {
            if (isset($_GET['upload'])) {
   $fbClient->setFileUploadSupport(true);
                $args = array('message' => 'some message');
                copy('http://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif', 'tmp/file.jpeg');
                $args['image'] = '@' . realpath('tmp/file.jpeg');
                $data = $fbClient->api('/me/photos', 'post', $args);
                unlink('tmp/file.jpeg');
                //assigning users to tag and cordinates
                $argstag = array('to' => $user);
                $argstag['x'] = 40;
                $argstag['y'] = 40;
                $datatag = $fbClient->api('/' . $data['id'] . '/tags', 'post', $argstag);
                echo 'Success! Check your facebook wall now';
            } else {
                Click here to upload this image on your facebook wall
            }
        }
The topic has been locked.
Support Specialist
11 years 7 months ago #27165 by alzander
The fileUploadSupport functions are in the Facebook library itself, not the jfbcLibrary. We have plans to derive our library from theirs eventually (probably in the v5.0 release), but need to do a lot of testing to make sure things to break. Until then, you need to call their client library and our JFBConnect library separately, like so:
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
$fbClient = $jfbcLibrary->getFbClient();
Then, you should just need to change all of your calls *except* $fbClient->setFileUploadSupport(true) to use $jfbcLibrary.

I think that should do it for you, but we've never tested the file upload functionality, so can't guarantee that will work.. just that that's how you should be calling the different libraries.

Keep me posted on how that goes!
Alex
The topic has been locked.
Active Subscriptions:

None
11 years 7 months ago #27195 by catedh
Hi Alex..

Thank you so much the code working as expected. I'm so glad. :D :rolleyes: :B:

Now I have problem about the login session. the scenario is:
user register/login on website. the logout button is totally hidden after logged in. user logout from facebook without logout from joomla
then user try to upload the picture (with not logged in from facebook still logged in in joomla) and get error:
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user.

How to achieve these:
1. if user not logged in from facebook. joomla will automatic logging out.
2. if user logged in from facebook, different user from joomla so joomla will logging out.

Or any other suggestion Alex?

--
I already post a rating and a review at the Joomla! Extensions Directory. Just waiting a moderation there. ^^
The topic has been locked.
Support Specialist
11 years 7 months ago #27208 by alzander
Catur,
First off, thanks for the review! We definitely appreciate it!

As for your issue, a few quick questions before I can give you a good answer...
* are user's allowed to register and login to your site with Joomla credentials or does every user *have* to login with Facebook / JFBConnect?
* If user's don't have to use Facebook, instead of logging them out automatically, can you update your code in some way to not show the upload ability to those that aren't currently logged into Facebook? I can help with this, just need to know if that would work for you.

Let us know.. just trying to come up with other ideas :)

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
11 years 7 months ago #27209 by catedh
Hi Alex,
off course we love to review for this great extension. My review comes up now on JED by fhu. :D

About my issues:
User only login and register with JFBConnect. I don't use Joomla login/registration. So I turned off other login. only facebook JFBConnect login.
For My code I still have this:
set_time_limit(50);
require_once JPATH_ROOT . DS . 'components' . DS . 'com_jfbconnect' . DS . 'libraries' . DS . 'facebook.php'; 
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
$fbClient = $jfbcLibrary->getFbClient();
$fbUser = $jfbcLibrary->getFbUserId();
$validate = $jfbcLibrary->validateToken();

if ($fbUser) {
} else {
    $validate = $jfbcLibrary->validateToken();
    header('Location:' . $validate . '&scope=user_photos,publish_stream');
}

// Login or logout url will be needed depending on current user state.
        if ($fbClient) {
            if (isset($_GET['upload'])) {
                $fbClient->setFileUploadSupport(TRUE);
                $args = array('message' => 'text messsage');
               	copy('image.jpg', 'tmp/file.jpeg');
                $args['image'] = '@' . realpath('tmp/file.jpeg');
                $data = $fbClient->api('/me/photos', 'post', $args);
                unlink('tmp/file.jpeg');
                //assigning users to tag and cordinates
                $argstag = array('to' => $fbUser);
                $argstag['x'] = 40;
                $argstag['y'] = 40;
                $datatag = $fbClient->api('/' . $data['id'] . '/tags', 'post', $argstag);
                header( 'Location: success.html' ) ;
            } else {
}
The topic has been locked.
Active Subscriptions:

None
11 years 6 months ago #27239 by catedh
Hi Alex,

still no update about this? :D
I'm so curiouss.... I have tried to modified but no luck at all.. =(

The main point is I just only want to use Facebook session for auto login and auto logout from joomla.
Still can't figure this out.

Thank you :D :D
The topic has been locked.
Support Specialist
11 years 6 months ago #27279 by alzander
Catur,
Very sorry for the delay. Needed to think about this a bit and do a little research as well...

First off, the validateToken() function will check if the user's current authentication token works. If not, it will try to re-authenticate them. It only returns a true/false value if they are actually authenticated though.. it doesn't return a URL that you can append extra scope parameters too.

If you want to add extra scope parameters, you can do so in the JFBConnect Config -> Facebook API settings area. That will request the permission from all users that login, just so you know.

Beyond that, I think it should do what you're looking.. just change your if ($fbClient) statement to if ($jfbcLibrary->validateToken()) call. I'm sure you may run into other issues, but hopefully that will help.

Keep me posted on what happens.

Thanks,
Alex
The topic has been locked.