Hello,
I've gone through the documentation several times, as well as several posts here... but cannot figure out why my GalleryEmbed::init is failing.
Here is how I'm calling it:
$g2URI = "/mg/";
$EmbedUri = "/media3.php";
$uid = $_SESSION['login_id']; // Numeric primary key, e.g. 1,2,3,4,5...
$uname = $_SESSION['login_user']; // username string, e.g. joebob1
$level = $_SESSION['login_level']; // numeric group level
$email = $_SESSION['Email']; // email string
$fname = $_SESSION['First']; // first name string
$lname = $_SESSION['Last']; // Last name String
$FullName = "$fname $lname";
// initiate G2
$ret = GalleryEmbed::init(array('g2Uri' => $g2URI, 'embedUri' => $EmbedURI, 'activeUserId' => $uid ));
if ($ret) {
/* Error! */
/* Did we get an error because the user doesn't exist in g2 yet? */
$ret2 = GalleryEmbed::isExternalIdMapped($uid, 'GalleryUser');
if ($ret2 && $ret2->getErrorCode() & ERROR_MISSING_OBJECT) {
/* The user does not exist in G2 yet. Create in now on-the-fly */
$ret = GalleryEmbed::createUser($uid, array('username' => $uname ));
if ($ret) {
/* An error during user creation. Not good, print an error or do whatever is appropriate
* in your emApp when an error occurs */
print "An error occurred during the on-the-fly user creation <br>";
print $ret->getAsHtml();
print "uid is $uid<br>";
exit;
}
} else {
/* The error we got wasn't due to a missing user, it was a real error */
if ($ret2) {
print "An error occurred while checking if a user already exists<br>";
print $ret2->getAsHtml();
}
print "An error occurred while trying to initialize G2<br>";
print $ret->getAsHtml();
print "uid is $uid<BR>";
exit;
}
}
As you can see, it's pretty much line for line from the examples, except it isn't working. If I load the script while I'm not logged in, it will load gallery as a guest user. If I'm logged in as any user. I see this:
An error occurred while trying to initialize G2
Error (ERROR_MISSING_OBJECT) : Missing object for 30
in modules/core/classes/GalleryStorage/GalleryStorageExtras.class at line 2075 (gallerycoreapi::error)
in modules/core/classes/GalleryStorage/GalleryStorageExtras.class at line 98 (gallerystorageextras::_identifyentities)
in modules/core/classes/GalleryStorage.class at line 298 (gallerystorageextras::loadentities)
in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 71 (mysqlstorage::loadentities)
in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 127 (galleryentityhelper_simple::loadentitiesbyid)
in modules/core/classes/GalleryCoreApi.class at line 2298 (galleryentityhelper_simple::loadentitybyexternalid)
in modules/core/classes/GalleryEmbed.class at line 215 (gallerycoreapi::loadentitybyexternalid)
in modules/core/classes/GalleryEmbed.class at line 120 (galleryembed::checkactiveuser)
in /home/bellzooc/public_html/media3.php at line 28 (galleryembed::init)
in /home/bellzooc/public_html/media3.php at line 111
uid is 1
The number relating to the missing object error changes based on what user is logged in, but it does not relate to the value stored in $uid, which you can see by the fact that I'm printing out that value when there is an error. (my initial thought was that the variable was broken, but that's not the case since it's showing the actual uid for the user.)
Anyone out there able to help me?
Posts: 1378
Daelic,
I have taken a very quick look at the code you posted..
A few issues..
Firstly if you INIT fails you cannot do a GalleryEmbed call, you be better off leaving out the userid in the init call and instead checking if the user is mapped and then logging the user in..(GalleryEmbed::checkActiveUser) that way you know the init call has failed due to other reasons (other than missing User ID)
A few other points, You have also only done a first level initialisation, and you will need to do a GalleryEmbed::handleRequest() or change your init to FULL
Hope this Helps
Wordpress Gallery2 Plug-in Downloads, Documentation & Support Gallery Embedded Community Site
Posts: 17
That worked like a charm, thanks!
I actually do have GalleryEmbed::handleRequest() running, I simply failed to include that fact above. My apologies.
I now have one more hurdle to overcome (user groups) and I'll be ready for the 'visual' part of my integration.