PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : [✔] Neue API - Cannot use object of type stdClass as array



Uranjitsu
08.04.2017, 12:44
Grüßt Euch,

ich weiß jetzt, nicht ob es an mir liegt oder an der API. Ich gehe aber von Ersteres aus und bitte um Hilfe.
Ich dachte das (http://stackoverflow.com/questions/20149556/php-content-type-not-specified-assuming-application-x-www-form-urlencoded) würde eventuell helfen, aber scheinbar kann eine Klasse nicht verwendet werden?



Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in D:\wamp\apache2\htdocs\xxx\includes\functions.php on line 112

Fatal error: Uncaught Error: Cannot use object of type stdClass as array in D:\wamp\apache2\htdocs\ssbgv2\includes\functions.p hp:117 Stack trace: #0 D:\wamp\apache2\htdocs\xxx\game.php(40): filecryptCC('http://ul.to/te...', '7985f3f72278079...', 'abb076e3ec08f6b...') #1 {main} thrown in D:\wamp\apache2\htdocs\xxx\includes\functions.php on line 117




function filecryptCC($links, $api, $foldername)
{
define('YES', 1);
define('NO', 0);
$USE_SSL = true;
$api_key = $api;
$name = $foldername;
$group = "";
$mirror_1 = $links;
$postdata = http_build_query(array(
"fn" => "containerV2",
"sub" => "create",
"api_key" => $api_key,
"name" => $name,
"mirror_1" => $mirror_1,
"captcha" => YES,
"allow_cnl" => YES,
"allow_dlc" => YES,
"allow_links" => NO,
"group" => $group,
));
$opts = array('http' => array(
"method" => "POST",
"content" => $postdata,
));
$context = stream_context_create($opts);
$result = file_get_contents('http' . (($USE_SSL) ? 's' : '') . '://www.filecrypt.cc/api.php', false, $context);
if (!$result) {
throw new Exception("filecrypt.cc api down");
} else {
$json = json_decode($result);
$fc_link = $json->container[0]->link;
$fc_simg = $json->container[0]->bigimg;
}

$fc_array = array(
$fc_link,
$fc_simg,
);
return ($fc_array);
}

Nimbus
08.04.2017, 14:41
Das 1. ist eine Notice, deren Bedeutung schwer zu beurteilen ist (hängt etwas davon ab, wie der Server darauf reagiert). Die sagt einfach nur, dass der content-type deiner Anfrage nicht angegeben ist.

Der 2. Fehler ist kritischer, da die Antwort scheinbar nicht die erwartete Form hat. Zum Debuggen könntest/solltest du den Inhalt von $result anschauen. Womöglich bekommst du dort Hinweise, warum die Anfrage fehlschlägt. Wenn in $result nicht das erwartete JSON-Objekt drin steckt, dann geht es schief, wenn du auf bestimmte Strukturen zugreifen möchtest.

Uranjitsu
08.04.2017, 15:17
Übergeben wird folgendes:

1 Link: uploaded.net (http://ul.to/xyz)
2 API-Key
3 Name

$result werde ich mir gleich mal anschauen.

LG

GipsyDanger
08.04.2017, 18:08
Hallo,

es muss $json->container->link; bzw. $json->container->bigimg ich werde die doku anpassen!
Danke für den Hinweis.

Uranjitsu
08.04.2017, 20:40
Super, Danke.

Uranjitsu
11.04.2017, 19:44
Kurz nochmal:
Die Notice erhalte ich weiterhin:

Notice: file_get_contents(): Content-type not specified assuming application/x-www-form-urlencoded in D:\wamp\apache2\htdocs\xxx\includes\functions.php on line 112

Ich habe das hier nun erweitert:

$opts = array('http' => array(
"method" => "POST",
"content" => $postdata,
));
Die Notice verschwindet mit:


$opts = array('http' => array(
"method" => "POST",
'header' => "Connection: close\r\n" .
"Content-type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($postdata) . "\r\n",
"content" => $postdata,
));


Ob das nun so weit ok ist, kann ich nicht sagen. Beim Crypten gibt es keine Probleme.

LG

Nimbus
11.04.2017, 22:09
Ob das nun so weit ok ist, kann ich nicht sagen
Ja, das sollte okay sein. Genau das sagt der Fehler ja aus (siehe oben).