myGully.com

myGully.com (https://mygully.com/index.php)
-   Entwicklung & Programmierung (https://mygully.com/forumdisplay.php?f=72)
-   -   PHP Anfänger am skripten (https://mygully.com/showthread.php?t=2960984)

TheHobbygangster 23.06.13 18:43

PHP Anfänger am skripten
 
Guten Abend

Wie im Titel schon steht habe ich nicht sehr viel Ahnung von PHP, trotzdem probierte ich etwas aus.. Was leider nicht wirklich funktionierte. Daher möchte ich nun von Euch gerne wissen ob dieses Skript überhaupt funktionieren kann.

Hier der Code:
Code:

<?php

    $url="https://api.instagram.com/v1/media/popular?access_token=143857791.3beac03.2bf4f508c1434eaaa4e9916416bc2880";
    $curl = curl_init();
    // Options
    curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_TIMEOUT => 4
    ));
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
    curl_close($curl);

    if($resp){
        $data=json_decode($resp, true);
        foreach($data['data'] as $images){
            $instgramfotos = array(
                'startDate' => $images['created_time'],
                'headline' => $images['caption']['text'],
                'text' => $images['caption']['text'],
                'asset' => array(
                array('media' => $images['images']['thumbnail']['url'],
                    'credit' => 'bal',
                    'caption' => 'blaa',
                ))
            )
    }}

    curl_close($curl);
    echo json_encode($instagramfotos);
 ?>

Ich hoffe Ihr könnt mir etwas weiterhelfen :T

MarkusT72 24.06.13 08:18

Ja es kann funktionieren, wenn die Fehler (syntaktisch und logisch) daraus entfernt sind. Weil heute die Sonne scheint hier mal die korrigierte Version :D

PHP-Code:

<?php
    $url
="https://api.instagram.com/v1/media/popular?access_token=143857791.3beac03.2bf4f508c1434eaaa4e9916416bc2880";
    
$curl curl_init();
    
// Options
    
curl_setopt_array($curl, array(
      
CURLOPT_RETURNTRANSFER => 1,
      
CURLOPT_URL => $url,
      
CURLOPT_TIMEOUT => 4,
      
// SSL Optionen setzen
      
CURLOPT_SSL_VERIFYPEER => 0,
      
CURLOPT_SSL_VERIFYHOST => 0
    
));
    
// Send the request & save response to $resp
    
$resp curl_exec($curl);

    if (
curl_errno($curl)) 
    {
        
// Fehlerausgabe
        
print curl_error($curl);
    } else {
        
$data=json_decode($resptrue);
        foreach(
$data['data'] as $images) {
           
$instagramfotos[] = array(  // Rückgabewert ist ein Array
                
'startDate' => $images['created_time'],
                
'headline' => $images['caption']['text'],
                
'text' => $images['caption']['text'],
                 
'asset' => array(
            
'media' => $images['images']['thumbnail']['url'],
                    
'credit' => 'bal',
                    
'caption' => 'blaa'
                
)
      );
    }
     }
    
curl_close($curl);
    echo 
json_encode($instagramfotos);
?>


TheHobbygangster 24.06.13 18:51

Ohh dankeschön! Wusste ich doch das auf Euch bzw. Dich verlass ist. Danke :T


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:17 Uhr.

Powered by vBulletin® (Deutsch)
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.