views:

209

answers:

1

On stream.get, I try to

echo $feeds["posts"][$i]["attachment"]["href"];

It return the URL, but, in the same array scope where "type" is located (which returns string: video, etc), trying $feeds["posts"][$i]["attachment"]["type"] returns nothing at all!

Here's an array through PHP's var_dump: http://pastie.org/930475

So, from testing I suppose this is protected by Facebook? Does that makes sense at all?

Here it's full: http://pastie.org/930490, but not all attachment/media/types has values.

It's also strange, because I can't access through [attachment][media][href] or [attachment][media][type], and if I try [attachment][media][0][type] or href, it gives me a string offset error.

["attachment"]=> array(8) {
    ["media"]=> array(1) {
        [0]=> array(5) {
            ["href"]=> string(55) "http://www.facebook.com/video/video.php?v=1392999461587"
            ["alt"]=> string(13) "IN THE STUDIO"
            ["type"]=> string(5) "video"

My question is, is this protected by Facebook? Or we can actually access this array position?

+1  A: 

Well, once the data is returned to you, it can no longer be protected by Facebook. You have full access to everything in that result as a regular data structure.

From the looks of it, there are multiple href properties throughout, so you'll want to be careful which one you're going for. $feeds["posts"][$i]["attachment"]["href"] is a valid element for some items, but $feeds["posts"][$i]["attachment"]["media"][0]["href"] is also a valid element.

There doesn't appear to be a $feeds["posts"][$i]["attachment"]["type"] element though, so that's why you're getting nothing for that particular item. There is a type inside ["attachment"]["media"][0] however, which is probably what you want.

If you are getting a string offset error when using array syntax, you've probably mixed up an element somewhere. Strings can be accessed via array syntax. For example:

$str = "string";
echo $str[1];  //echos 't'

You would get an offset warning if you tried to access an index that was larger than the string. In any case, from the looks of that output, $feeds["posts"][$i]["attachment"]["media"][0]["type"] should work.

zombat
This was solved ;D I found that media, contained a array, so simply done some foreach loop, to access the values. Thanks guys!