0

I am using the Behance API (https://github.com/behance/network_api_php) to try to extract a project's image.

I have been able to successfully code for the project name and URL, but the cover image has me stumped.

I have this in my PHP code..

<?php
foreach($api->getUserProjects( 'username' ) as $beproj): ?>
<h1><?php echo $beproj->name; ?></h1>
<a href="<?php echo $beproj->url; ?>"><?php echo $beproj->name; ?></a><br />
  <img src="<?php echo $beproj->covers[202]; ?>"> 
<?php endforeach; ?>

This outputs the name and URL perfectly, but the 202 pixel size cover image just won't show up. Can someone please tell me the right way to extract the 202 image?

An array from the Behance API looks something like this..

Array
(
[0] => stdClass Object
    (
        [id] => 18848121
        [name] => Sketchbook
        [published_on] => 1407253953
        [created_on] => 1407251608
        [modified_on] => 1407451145
        [url] => https://www.behance.net/gallery/18848121/Sketchbook
        [privacy] => public
        [fields] => Array
            (
                [0] => Graphic Design
                [1] => Icon Design
                [2] => Illustration
            )

        [covers] => stdClass Object
            (
                [404] => https://m1.behance.net/rendition/projects/18848121/404/2e0cadfd1167f2bdf89decce172e5e8f.jpeg
                [202] => https://m1.behance.net/rendition/projects/18848121/orig/2e0cadfd1167f2bdf89decce172e5e8f.jpeg
                [230] => https://m1.behance.net/rendition/projects/18848121/230/2e0cadfd1167f2bdf89decce172e5e8f.jpeg
                [115] => https://m1.behance.net/rendition/projects/18848121/115/2e0cadfd1167f2bdf89decce172e5e8f.jpeg
            )

        [mature_content] => 0
        [mature_access] => allowed
        [owners] => Array
            (
                [0] => stdClass Object
                    (
                        [id] => 215057
                        [first_name] => Mike
                        [last_name] => 
                        [username] => creativemints
                        [city] => Prague
                        [state] => 
                        [country] => Czech Republic
                        [location] => Prague, Czech Republic
                        [company] => Creative Mints
                        [occupation] => 
                        [created_on] => 1281693887
                        [url] => https://www.behance.net/creativemints
                        [images] => stdClass Object
                            (
                                [50] => https://mir-cdn.behance.net/v1/rendition/user/50/215057.53ac6f3dacec6.jpg
                                [115] => https://mir-cdn.behance.net/v1/rendition/user/115/215057.53ac6f3dacec6.jpg
                                [138] => https://mir-cdn.behance.net/v1/rendition/user/138/215057.53ac6f3dacec6.jpg
                            )

                        [display_name] => Mike
                        [fields] => Array
                            (
                                [0] => Illustration
                                [1] => UI/UX
                                [2] => Game Design
                            )

                    )

            )

        [stats] => stdClass Object
            (
                [views] => 4510
                [appreciations] => 1307
                [comments] => 65
            )

        [for_sale] => 0
    )

Thanks in advance for all your help.

1
  • I just figured this out using echo $beproj->covers->{'202'} Now it works!!! Commented Aug 8, 2014 at 19:51

2 Answers 2

1

You're accessing "covers" as an array but in fact, it is an object.

[covers] => stdClass Object

What about:

echo $beproj->covers->{'202'}
Sign up to request clarification or add additional context in comments.

3 Comments

I did try that.. I get this.. Parse error: syntax error, unexpected '202' (T_LNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'
You are right. See my edited answer. This should work.
Thanks, I had figured it out, since I didn't have enough rep points, I couldn't answer my own question. I had posted a comment below the question. Thanks for your time again..
0

The answer was simple enough.. I needed to use

$beproj->covers->{'202'} 

instead of

$beproj->covers->['202']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.