waylaidwanderer / PHP-SteamCommunity

A PHP library for interacting with the Steam Community website (steamcommunity.com)
MIT License
77 stars 41 forks source link

Protocol steammobile not supported or disabled in libcurl #26

Open saqwel opened 8 years ago

saqwel commented 8 years ago

I know Trade offers works fine with PHP 5.6 from another server (with another configuration). But I have PHP 7.0.3. I configure it and install. Authentication work fine. But when I trying to execute $tradeId = $trade->sendWithToken( $some_token ); $tradeId is return as 0. To SteamCommunity.php in public function cURL($url, $ref = null, $postData = null) was added echo curl_error($ch); Result: Protocol steammobile not supported or disabled in libcurl. How does enable steammobile protocol or make protocol redirect?

waylaidwanderer commented 8 years ago

Show me your entire code, none of the above stuff has "steammobile" in the URL.

saqwel commented 8 years ago

I don't find "steammobile" too. But can't find what that error mean. My code: I had rewrite your example:

require '/web/composer/vendor/autoload.php';

use waylaidwanderer\SteamCommunity\Enum\LoginResult;
use waylaidwanderer\SteamCommunity\MobileAuth\WgTokenInvalidException;
use waylaidwanderer\SteamCommunity\SteamCommunity;

$settings   = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/_steam/settings.json'), true);
$steam      = new SteamCommunity($settings, $_SERVER['DOCUMENT_ROOT'] . '/_steam' );

$steam->setTwoFactorCode($steam->mobileAuth()->steamGuard()->generateSteamGuardCode());
$loginResult = $steam->doLogin();

while ($loginResult != LoginResult::LoginOkay) {
    if ($loginResult == LoginResult::Need2FA) {
        if ($steam->mobileAuth()->steamGuard() == null) {
            //$authCode = 'Enter 2FA code: ';
            //$steam->setTwoFactorCode($authCode);
        } else {
            $authCode = $steam->mobileAuth()->steamGuard()->generateSteamGuardCode();
            $steam->setTwoFactorCode($authCode);
            //echo 'Generated Steam Guard code: ' . $authCode . '<br>';
            $loginResult = $steam->doLogin();
        }
    } else if ($loginResult == LoginResult::NeedEmail) {
        $authCode = 'Enter Steam Guard code from email: ';
        $steam->setEmailCode($authCode);
        $loginResult = $steam->doLogin();
    } else if ($loginResult == LoginResult::NeedCaptcha) {
        $captchaCode = 'Enter captcha (' . $steam->getCaptchaLink() . '): ';
        $steam->setCaptchaText($captchaCode);
        $loginResult = $steam->doLogin();
    } else {
        break;
    }
    echo "Login result: ".$loginResult."<br>";
}

if ($loginResult == LoginResult::LoginOkay) {
    $tradeOffers = $steam->tradeOffers();
    //var_dump($tradeOffers->getTradeOffersViaAPI(true));

    $trade = $tradeOffers->createTrade('307769701');
    $trade->addOtherItem(730, 2, '4813427756');
    $tradeId = $trade->sendWithToken('307769701');
    //$tradeId = $trade->send();
    var_dump($tradeId).'<br>';

    try {
        $confirmations = $steam->mobileAuth()->confirmations()->fetchConfirmations();
        foreach ($confirmations as $confirmation) {
            $tradeIdConfirm = $steam->mobileAuth()->confirmations()->getConfirmationTradeOfferId($confirmation);
            echo $tradeIdConfirm.'<br>';
            if( $tradeId==$tradeIdConfirm ) {
                var_dump($steam->mobileAuth()->confirmations()->acceptConfirmation($confirmation));
            }
        }
    } catch (WgTokenInvalidException $ex) {
        // session invalid
        $steam->mobileAuth()->refreshMobileSession();
    }
}

Add one string to your function echo curl_error($ch); for troubleshooting:

public function cURL($url, $ref = null, $postData = null)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
        if (!empty($this->rootDir)) {
            curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_getCookieFilePath());
            curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_getCookieFilePath());
        }
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        if ($this->mobile) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Requested-With: com.valvesoftware.android.steam.community"]);
            curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.1.1; en-us; Google Nexus 4 - 4.1.1 - API 16 - 768x1280 Build/JRO03S) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
            curl_setopt($ch, CURLOPT_COOKIE, $this->buildCookie(self::$DEFAULT_MOBILE_COOKIES));
        } else {
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0');
        }
        if (isset($ref)) {
            curl_setopt($ch, CURLOPT_REFERER, $ref);
        }
        if (isset($postData)) {
            curl_setopt($ch, CURLOPT_POST, true);
            $postStr = "";
            foreach ($postData as $key => $value) {
                if ($postStr)
                    $postStr .= "&";
                $postStr .= $key . "=" . $value;
            }
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);
        }
        curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_ALL);
        $output = curl_exec($ch);
        echo curl_error($ch);
        curl_close($ch);
        return $output;
    }
waylaidwanderer commented 8 years ago

One thing I noticed is that your trade token is incorrect. $tradeId = $trade->sendWithToken('307769701'); This is the accountId, not the tradeToken.

saqwel commented 8 years ago

You can check "accountid_other" in this trade offer: http://api.steampowered.com/IEconService/GetTradeOffer/v1/?tradeofferid=1034071107&language=english&key=<enter your api key here> This code works correctly from another server. Your code work well, my data is correct. But I think I have wrong configuration of PHP. Main question: What does mean Protocol steammobile not supported or disabled in libcurl?

saqwel commented 8 years ago

Ohh! I understand what you mean when say "This is the accountId, not the tradeToken". I send my trade offer to my friend and this is not important what I use like parameter for function. If I send my trade offer to stranger with wrong token I get error Error: There was an error sending your trade offer. Please try again later. (15).

waylaidwanderer commented 8 years ago

Before echo curl_error($ch);, can you also echo $url;?

saqwel commented 8 years ago

This is last $url before error: https://steamcommunity.com/mobileconf/conf?p=android:fab585dd-d3ce-85dd-85dd-85ddd3ce7d34&a=0&k=XDxAON/kRTpewIqWyz2cdHOKQYg=&t=1456278550&m=android&tag=conf

CyanoFresh commented 8 years ago

@saqwel &a parameter shouldn't be 0.