Hi,

I'm trying to get page id with code that Dave provided, but get this strange error every time:

Fatal error: Call to a member function getSignedRequest() on a non-object in /home/likeid/public_html/sites/all/modules/rules/rules/modules/php.rules.inc(107) : eval()'d code on line 2

The code is next:

extract(fb_vars());
$sr = $fb->getSignedRequest();
echo $sr->page->id;

I put this code in php snippet. What am I missing here?

Comments

Dave Cohen’s picture

The $fb is not always initialized. so put a if ($fb) { ... } after the extract().

Usually there will be a $fb, on all canvas pages, and on regular pages when there is a "primary" app. If not, there will only be an $fb when some code has explicitly initialized it.

krembo’s picture

So you mean if someone visit my application at page tab, the $fb will be initialized?

Dave Cohen’s picture

Yes, on a page tab, the $fb should be initialized.

krembo’s picture

Thanks, Dave.

I tried that. Now there are no errors, but it still doesn't work... How can I initialize $fb in code?

krembo’s picture

Maybe you can help me with that in other way. When user in facebook entering page tab with my application,
I want to redirect him on one page if he is admin(sort of admin panel ),
and on the other if he is usual user(get the page id and redirect to "page/HERE-GOES-PAGE-ID").

And second thing get the page id, and put it in some field in content type.

krembo’s picture

Update:
Just the second question still not solved.

krembo’s picture

Both solved, but I used external function to make this happen...
Would like to know why it didn't work with getSignedRequest()

Dave Cohen’s picture

Status: Active » Fixed

So fixed?

If you have a useful solution, please share it.

krembo’s picture

It's actually work around with code that i have found on the net.

function parsePageSignedRequest() {
if (isset($_REQUEST['signed_request'])) {
$encoded_sig = null;
$payload = null;
list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
return $data;
}
return false;
}

if($signed_request = parsePageSignedRequest()) {
	if($signed_request->page->admin) {
		drupal_goto('http://example.com/node/1');
	} else {
		drupal_goto('http://example.com/page/'.$signed_request->page->id);
	}

This is the snippet I used for redirect the admin/non admin.

And the second one is to add this string in code:

echo  "<a href='node/2?pageid=".$signed_request->page->id."'>click here</a>";

And then just put the value into the hidden field in webform, that placed on 'node/2'.
After that just one Rule and field populated with desired value.

I know this isn't the best solution in drupal. Just couldn't make it work with DFF. Still would like to know if it possible.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.