Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Chit-Chat (http://www.chiefdelphi.com/forums/forumdisplay.php?f=14)
-   -   libgmailer experience? (http://www.chiefdelphi.com/forums/showthread.php?t=38844)

MrToast 05-07-2005 23:27

libgmailer experience?
 
Hi all,

I'm trying to set up a page on my site to use libgmailer, an open source set of PHP classes for remotely connecting to Gmail.

What I'm trying to do is figure out how many invitations I have left. Unfortunately, nothing's working.

Here's the code of my main "gmail.php" file:
Code:

<?php
        require_once("libgmailer.php");
        $gmail = new GMailer();
        $gmail->setLoginInfo("mrtoast@gmail.com","mypassword",0);
        $gmail->connect();
        $gmail->fetchBox(GM_STANDARD, "inbox", 0);
        $info = $gmail->getInfo();
        var_dump($info);
        $gmail->disconnect();
?>

At first you may think "Oh, well your obvious problem is that there's no such function as "getInfo()". And you're right. Except that I've picked apart the code for Gallina, a gmail-based blogging system and added the getInfo function to libgmailer:
Code:

function getInfo() {
        $snapshot = $this->getSnapshot(GM_STANDARD);
        $info = array();
        if ($snapshot) {
                $info["quota"]["MB"] = $snapshot->quota_mb;
                $info["quota"]["Percentage"] = $snapshot->quota_per;
                $info["invitations"] = $snapshot->have_invit;
                $info["labels"] = $snapshot->label_list;
                $info["total"] = $snapshot->box_total;
        }
        return $info;
}

Unfortunately, the var_dump is producing nothing but this:
Code:

array(4) {
  ["quota"]=>
  array(2) {
    ["MB"]=>
    NULL
    ["Percentage"]=>
    NULL
  }
  ["invitations"]=>
  NULL
  ["labels"]=>
  NULL
  ["total"]=>
  NULL
}

If anyone has any experience with this, I'd love for someone to help me figure out where I'm screwing up. Feel free to IM me, email, post here, whatever.

Thanks!

Dave

Mike 05-07-2005 23:46

Re: libgmailer experience?
 
Quote:

Originally Posted by MrToast
Code:

function getInfo() {
        $snapshot = $this->getSnapshot(GM_STANDARD);
        $info = array();
        if ($snapshot) {
                $info["quota"]["MB"] = $snapshot->quota_mb;
                $info["quota"]["Percentage"] = $snapshot->quota_per;
                $info["invitations"] = $snapshot->have_invit;
                $info["labels"] = $snapshot->label_list;
                $info["total"] = $snapshot->box_total;
        }
        return $info;
}


When you call getSnapshot, your only have the $type parameter set (GM_STANDARD), but in the class GMailSnapshot constructor it also has a $raw parameter. There is an if statement which decides whether or not to set $this->have_invit;
Code:

if (isset($raw["i"][1])) $this->have_invit = $raw["i"][1];
But, $raw isn't set. Maybe try something like
Code:

function getInfo() {
        $raw = array(
                  "i" => array(TRUE),
                  "gn" => array(TRUE),
                  "v" => array(TRUE)
                );
        $snapshot = $this->getSnapshot(GM_STANDARD);
        $info = array();
        if ($snapshot) {
                $info["quota"]["MB"] = $snapshot->quota_mb;
                $info["quota"]["Percentage"] = $snapshot->quota_per;
                $info["invitations"] = $snapshot->have_invit;
                $info["labels"] = $snapshot->label_list;
                $info["total"] = $snapshot->box_total;
        }
        return $info;
}

That array setup may be fubar, as I've never dealt with multi-dimensional arrays in this sense...

EDIT (Again): Just looked over the code, and $this->have_invit is set from the array put in as a parameter, so I don't think you can get the amount of invites from calling this function =(

Maybe some creative use of sockets and regular expression functions would let you parse the info out?


MrToast 05-07-2005 23:58

Re: libgmailer experience?
 
I think that $raw IS set, because I call:
$gmail->fetchBox(GM_STANDARD, "inbox", 0);

Looking through this, we see it fires:
Code:

$this->fetch($q);
And then looking at the fetch function we see the line:
Code:

$this->raw = $packets;
So $raw is getting set. But I've just found something interesting...
In this same fetch function, the data returned from GMail is in the $inbox variable. I shot it out to HTML via:
Code:

echo "<textarea>".$inbox."</textarea>";
This is what's in the textarea:
Code:

<script>top.location="https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%3Fui%3Dhtml%26zy%3Dl";</script>
Any idea what's up with that?

Thanks!

Dave

Mike 06-07-2005 00:09

Re: libgmailer experience?
 
Try echo'ing out $this->raw after it's set in fetch()

MrToast 06-07-2005 00:14

Re: libgmailer experience?
 
It's an empty array:
Code:

array(0) { }
Grrrrr.... time to contact the developer.... :p

Dave

Mike 06-07-2005 00:21

Re: libgmailer experience?
 
Quote:

Originally Posted by MrToast
It's an empty array:
Code:

array(0) { }
Grrrrr.... time to contact the developer.... :p

Dave

Yeah, it'd take a while for someone to learn how he structured the code. Odds are it's being set somewhere else as well.


All times are GMT -5. The time now is 03:36.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi