I use yahoo messenger api for sending bulk chat messages to different groups(which is define by us for different package users ) but after some time JYMSG API automatically sign off How can we stay sign in?

    <?php
    error_reporting(0);
    include("includes/dbconn.php");
    function sendreq($mid)
    {
        $sql = mysql_query("select * from cv_requests where medium = 'yahoo' and medium_id = '".$mid."'");
        if(mysql_num_rows($sql) > 0)
        {
            return 'already available';
        }
        else
        {
            mysql_query("insert into cv_requests (medium, medium_id) values ('yahoo', '".$mid."')");
            return 'not available';
        }
    }

    /*
     *
     *Software Copyright License Agreement (BSD License)
     *
     *Copyright (c) 2010, Yahoo! Inc.
     *All rights reserved.
     *
     *Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
     *
     ** Redistributions of source code must retain the above
     *  copyright notice, this list of conditions and the
     *  following disclaimer.
     *
     ** Redistributions in binary form must reproduce the above
     *  copyright notice, this list of conditions and the
     *  following disclaimer in the documentation and/or other
     *  materials provided with the distribution.
     *
     ** Neither the name of Yahoo! Inc. nor the names of its
     *  contributors may be used to endorse or promote products
     *  derived from this software without specific prior
     *  written permission of Yahoo! Inc.
     *
     *THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
    */
    $sqlytalk = mysql_query("select * from cv_yahoo");
    $rowy = mysql_fetch_array($sqlytalk);        
    define('USERNAME', $rowy['username']);
    define('PASSWORD', $rowy['password']);
    define('CONSUMER_KEY', $rowy['cons_key']);
    define('SECRET_KEY', $rowy['sec_key']);
    include_once 'jymengine.class.php';
    $engine = new JYMEngine(CONSUMER_KEY, SECRET_KEY, USERNAME, PASSWORD);
    $engine->debug = true;

    if ($engine->debug) echo '> Fetching request token'. PHP_EOL;
    if (!$engine->fetch_request_token()) die('Fetching request token failed');

    if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
    if (!$engine->fetch_access_token()) die('Fetching access token failed');

    if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
    if (!$engine->signon('CapitalVia Logged In')) die('Signon failed first');

    $seq = -1;
    while (true)
    {        
            $resp = $engine->fetch_long_notification($seq+1);
            if ($resp === 'error') 
            {        
                    if ($engine->get_error() != -10)
                    {                            

                    if ($engine->debug) echo '> Fetching access token'. PHP_EOL;
                    if (!$engine->fetch_access_token()) die('Fetching access token failed');

                    if ($engine->debug) echo '> Signon as: '. USERNAME. PHP_EOL;
                    if (!$engine->signon('CapitalVia Logged In')) die('Signon failed loop');

                    $seq = -1;
                    }

                    // Add customers
                    $sqlgetcustomers = mysql_query("select distinct cs.yahoo from cv_customers as cs, cv_requests as rq where cs.yahoo != '' and cs.yahoo != rq.medium_id");
                    if(mysql_num_rows($sqlgetcustomers) > 0 )
                    {
                        while($rowcust = mysql_fetch_array($sqlgetcustomers))
                        {
                            $arrmediumcust = explode("@",$rowcust['yahoo']);
                            if(is_array($arrmediumcust))
                            {
                                $rowcust['yahoo'] = $arrmediumcust[0];
                            }
                            if(sendreq($rowcust['yahoo']) == 'not available')
                            {
                                $engine->add_contact($rowcust['yahoo']);
                            }
                        }
                    }

                    // Send message and signout
                    $sqlytalk = mysql_query("select * from cv_yahoo");
                    $rowy = mysql_fetch_array($sqlytalk);
                    if($rowy['isstart']    == '0')
                    {
                        $engine->signoff();
                        die();
                    }                        
                    $sqlcontinue = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");        
                    if(mysql_num_rows($sqlcontinue) < 1)
                    {
                        continue;
                    }
                    $sql = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");    
                    if(mysql_num_rows($sql) > 0)
                    {
                        while($rowsql = mysql_fetch_array($sql))
                        {
                            $arrmedium = explode("@",$rowsql['medium_id']);
                            if(is_array($arrmedium))
                            {
                                $rowsql['medium_id'] = $arrmedium[0];
                            }                            
                            if(sendreq($rowsql['medium_id']) == 'not available')
                            {
                                $engine->add_contact($rowsql['medium_id']);
                            }
                            $engine->send_message($rowsql['medium_id'], json_encode($rowsql['message']));
                            mysql_query("update cv_messages set issent = 1 where id = ".$rowsql['id']);
                         }    
                    }
                    continue;
            }
            else
            {        

                $response_array = $resp;
                foreach($response_array as $resrow)
                {
                    foreach($resrow as $key=>$val)
                    {

                        if ($val['sequence'] > $seq) $seq = intval($val['sequence']);            
                        /*
                         * do actions
                         */
                        if ($key == 'buddyInfo') //contact list
                        {

                            if (!isset($val['contact'])) continue;

                            if ($engine->debug) echo PHP_EOL. 'Contact list: '. PHP_EOL;



                            foreach ($val['contact'] as $item)
                            {
                                if ($engine->debug) echo $item['sender']. PHP_EOL;
                            }
                            if ($engine->debug) echo '----------'. PHP_EOL;
                        }
                        if ($key == 'message') //incoming message
                        {
                            if ($engine->debug) echo '+ Incoming message from: "'. $val['sender']. '" on "'. date('H:i:s', $val['timeStamp']). '"'. PHP_EOL;
                            if ($engine->debug) echo '   '. $val['msg']. PHP_EOL;
                            if ($engine->debug) echo '----------'. PHP_EOL;

                            //reply
                            $words = explode(' ', trim(strtolower($val['msg'])));


                            if ($words[0] == 'yahoobotbandhoja123')
                            {
                                $engine->send_message($val['sender'], json_encode("Good Bye - CapitalVia"));
                                $engine->signoff();
                                die();                        
                            }
                        }
                        else if ($key == 'buddyAuthorize') //incoming contact request
                        {
                            if ($engine->debug) echo PHP_EOL. 'Accept buddy request from: '. $val['sender']. PHP_EOL;                    
                            if ($engine->debug) echo '----------'. PHP_EOL;    
                            if (!$engine->response_contact($val['sender'], true, 'Welcome to CapitalVia Yahoo'))
                            {
                                $engine->delete_contact($val['sender']);
                                $engine->response_contact($val['sender'], true, 'Welcome to CapitalVia Yahoo');
                            }
                        }
                    }
                }        

                    // Add customers
                    $sqlgetcustomers = mysql_query("select distinct cs.yahoo from cv_customers as cs, cv_requests as rq where cs.yahoo != '' and cs.yahoo != rq.medium_id");
                    if(mysql_num_rows($sqlgetcustomers) > 0 )
                    {
                        while($rowcust = mysql_fetch_array($sqlgetcustomers))
                        {
                            $arrmediumcust = explode("@",$rowcust['yahoo']);
                            if(is_array($arrmediumcust))
                            {
                                $rowcust['yahoo'] = $arrmediumcust[0];
                            }
                            if(sendreq($rowcust['yahoo']) == 'not available')
                            {
                                $engine->add_contact($rowcust['yahoo']);
                            }
                        }
                    }

                    // Send message and signout
                    $sqlytalk = mysql_query("select * from cv_yahoo");
                    $rowy = mysql_fetch_array($sqlytalk);
                    if($rowy['isstart']    == '0')
                    {
                        $engine->signoff();
                        die();
                    }                        
                    $sqlcontinue = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");        
                    if(mysql_num_rows($sqlcontinue) < 1)
                    {
                        continue;
                    }
                    $sql = mysql_query("select * from cv_messages where issent = 0 and medium = 'yahoo'");    
                    if(mysql_num_rows($sql) > 0)
                    {
                        while($rowsql = mysql_fetch_array($sql))
                        {
                            $arrmedium = explode("@",$rowsql['medium_id']);
                            if(is_array($arrmedium))
                            {
                                $rowsql['medium_id'] = $arrmedium[0];
                            }                            
                            if(sendreq($rowsql['medium_id']) == 'not available')
                            {
                                $engine->add_contact($rowsql['medium_id']);
                            }
                            $engine->send_message($rowsql['medium_id'], json_encode($rowsql['message']));
                            mysql_query("update cv_messages set issent = 1 where id = ".$rowsql['id']);
                         }    

                    }
                    continue;
            }
            continue;
    }
    ?>

In the manual it is stated than you can specify keepalive for your session. Look into that to prevent automatic logoff.

In the manual it is stated than you can specify keepalive for your session. Look into that to prevent automatic logoff.

pritaeas

thanks for reply sorry for my bed English I can't understand that

pritaeas

thanks for help. I thing it will work.

If you get it working, please post your solution here too. It might help others. (Just the part for the keep-alive)

I made some changes in jymengin.php

  1. set constent in class JYMEngine on line no. 42.

    /*Vishal code*/
    const URL_YM_KEEPALIVE='http://developer.messenger.yahooapis.com/v1/session/keepalive';
    
    //--/v1/session/keepalive?sid=msgrsessionid&notifyServerToken=1 
    /*#Vishal code*/
    
  2. add 1 new Function on line no. 71

    /*Vishal code*/
    public function keep_live()
    {
        //prepare url
        $url = $this::URL_YM_KEEPALIVE;
        $url .= '?sid='. $this->_config['username'];
        $url .= '?notifyServerToken=1';
    
        $rs = $this->curl($url);    
        if (stripos($rs, 'RequestToken') === false) return false;
        $request_token = trim(str_replace('RequestToken=', '', $rs));
        $this->_token['request'] = $request_token;
    
        return true;
    }
    /*#Vishal code*/
    

but I didn't test it yet.

Hello pritaeas

Please Help me. I am using yahoo messenger API (jymengine.class.php) but after run script session die on client side and live on yahoo server(Status Visible) after a time (1hour, 2hour or 2 days) . how can i resolve this problem.

I really don't know enough about this API as to determine what would cause this. You can try the Yahoo Groups.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.