Jump to content

Passing a JSON array into a function?


nitromaster

Recommended Posts

Hi

 

I need to pass in information via a JSON to a function.

 

The JSON array is as follows

{"canvas_url":"http://www.site.com/someurl/"}

Need to pass that into

$facebook->api_client->admin_setAppProperties($jsonarray);

where $jsonarray = that array

 

Of course

$facebook->api_client->admin_setAppProperties({"canvas_url":"http://www.site.com/someurl/"});

doesnt work. Neither does

$jsonarray = '{"canvas_url":"http://www.site.com/someurl/"}';
$facebook->api_client->admin_setAppProperties($jsonarray);

I've tried countless other things I could think about but still failed. What should I be looking at doing with the array? I had a  look at json encode/decode as well but these seem not useful to me as I'm working with total static arrays.

 

Thanks

Link to comment
Share on other sites

My guess is that the Facebook PHP Library will encode the JSON data for you. so try this:

$props = array(
  'canvas_url' => "http://www.site.com/someurl/",
);
$facebook->api_client->admin_setAppProperties($props);

Link to comment
Share on other sites

My guess is that the Facebook PHP Library will encode the JSON data for you. so try this:

$props = array(
  'canvas_url' => "http://www.site.com/someurl/",
);
$facebook->api_client->admin_setAppProperties($props);

Hi

Thanks for the reply, and pointing me towards what I should be doing.

Yes, the facebook libary does actually enocde the data, should have read through it first :)

 

Your way seems like it should work...but no matter what i seem to run into an error of something with the " => " bit when defining the array.

I haven't really used arrays like so, much, recently.

it's giving the following error

PHP Parse error:  syntax error, unexpected T_STRING in /home/mysite/set.php on line 19

Line 19 is

  'canvas_url' => "http://www.site.com/someurl/",

I've only been able to get other errors, when trying it some other way

like

PHP Parse error:  syntax error, unexpected T_DOUBLE_ARROW

PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

 

Any idea?

 

Thanks

 

 

And thanks to the rest of the repliers :)

Link to comment
Share on other sites

 <?php
//Make sure you are using the array construct especially for older versions of PHP.
$props = array( 'canvas_url' => 'http://www.site.com/someurl/');
?>

Still nothing.

Maybe my problem lies elsewhere?

PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING on that line.

Might be due to my version/set of php or whatever? (although i am using php 5)

Thanks

Link to comment
Share on other sites

it probably has to do something before that. can you post all the code or at least the 10 lines before the problem line.

Hi

Full file is

 

<?
require_once 'facebook.php';
require_once 'config.php';
$bebo = new Facebook($FACEBOOK_API, $FACEBOOK_SECRET);
$props = array( 'canvas_url' => 'http://www.site.com/someurl/');
$facebook->api_client->admin_setAppProperties($props);
?>

Link to comment
Share on other sites

There are no syntax errors there. Is the Parse Error you are getting in this file or one of the included files?

It's in this file. To make sure it wasn't facebook.php, I changed to bebo (they have a compatible api/libary) to test first. And also removed config.php and just put the variables in this file.

 

set.php

<?
require_once 'bebo.php';
$BEBO_API="YQmEbXMjdYTW38y00000000000000000000t";
$BEBO_SECRET="1lpji7Bto0jZyB6h600000000000000000000";
$bebo = new Bebo($BEBO_API, $BEBO_SECRET);
$props = array( 'canvas_url' => 'http://www.mysite.com/7/');
$bebo->api_client->admin_setAppProperties($props);
?>

 

PHP Parse error:  syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/mysite/public_html/set.php on line 6

 

Really going over my head tbh. =/

 

Any ideas?

Link to comment
Share on other sites

There must be some hidden character in there. Try creating a new file and retyping it.

 

<?php
require_once 'bebo.php';
$BEBO_API="YQmEbXMjdYTW38y00000000000000000000t";
$BEBO_SECRET="1lpji7Bto0jZyB6h600000000000000000000";
$bebo = new Bebo($BEBO_API, $BEBO_SECRET);
$props = array( 'canvas_url' => 'http://www.mysite.com/7/');
$bebo->api_client->admin_setAppProperties($props);
?>

Link to comment
Share on other sites

Ya, something's odd there.

 

It shouldn't make a difference, but you should also try using full php tags instead of the short tags. That can cause strange happenings on a server that's not configured to use them.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.