I been try us this module today
Post as user seams work ok but not post as admin. It return me:

Message: (#200) This API call requires a valid app_id.
Type: :OAuthException
Code: 200
User: :uid 

Not sure if I should provide somehow :uid (?)

Comments

fotuzlab’s picture

The message says "This api cal lrequires a valid app_id"
Could you please confirm your app id and app secret at 'admin/config/people/facebook_page_rules' are same as the ones you provided for fboauth?

ShadowMonster’s picture

Yes I check it few times to be sure.
As I wrote post as user is working but not post as admin.
Also I have to change Deprecate offline access: to disabled for FB do not return me error when authorize app. Is there some other requirements for App settings on FB?

ShadowMonster’s picture

Status: Active » Needs work

I Debug little a bit and I found problem:

in function function facebook_page_rules_post_to_wall_as_admin there is not getting access token so I made fast fix

function facebook_page_rules_post_to_wall_as_admin($message, $link, $name, $caption, $description) {

  //$access_token = variable_get('facebook_page_rules_page_token', NULL);
  global $user;
  $access_token = facebook_rules_get_token($user->uid);
  facebook_page_rules_post($message, $link, $name, $caption, $description, $access_token);
}
fotuzlab’s picture

To post to wall as admin, we need page access token which is different from user's access token. It is stored as a variable named 'facebook_page_rules_page_token'
This module does not use offline_access. Hence disabling/enabling it should not be effective.

I gave it a few trials and could not reproduce the issue.
Could you do the following and let me know the results. It would help me get closer to the issue.

  1. Confirm you have admin rights of the facebook page you want to post as admin. You can post to page as user even if you have just liked the page, but to post as admin, user who configured the module settings should be the admin of the facebook page.
  2. Save the configuration settings again and try to post. In case of failure, please post the watchdog error in case it is different from above.

Moreover, there are a few issues left to be fixed. I'll look into them this weekend. Hopefully, there would be a stable release soon.

ShadowMonster’s picture

Well, I'm sure I been doing everything right - in my case:

$access_token = variable_get('facebook_page_rules_page_token', NULL);

just do not return access token like it is not saving to this variable.

I check variable table in DB there is not facebook_page_rules_page_token so maybe it is problem when installing your module and the variable is not created anyway lets see if other will have this problem

fotuzlab’s picture

Status: Needs work » Active

This variable is stored when you save the configuration. (line #62 in facebook_page_rules.inc)
If you see status message as 'Configuration saved', it should be set. Else you see a warning message.

I created a new facebook page with default settings. It is working fine for me.
Check this link http://www.facebook.com/pages/Test/360107460707532

PS: Are you using latest dev version?

Josher’s picture

Running latest dev version and having the same issue.

Receive these notices when saving App ID/ Secret configuration.

Notice: Undefined index: error in facebook_page_rules_generate_token() (line 88 of sites/all/modules/facebook_page_rules/facebook_page_rules.module).
Notice: Undefined index: error in facebook_page_rules_generate_token() (line 88 of sites/all/modules/facebook_page_rules/facebook_page_rules.module).
Notice: Undefined index: error in facebook_page_rules_generate_token() (line 88 of sites/all/modules/facebook_page_rules/facebook_page_rules.module).
ShadowMonster’s picture

Well and this is the point.

I been look into this file. function facebook_page_rules_validate is never called so to fix it I have to add:

$form['#validate'][] = 'facebook_page_rules_validate';

to facebook_page_rules_settings_form function

also $access_token is not received from variable so I have to do:

function facebook_page_rules_validate() {

  global $user;
  $access_token = facebook_rules_get_token($user->uid);

after it it make it work correctly and variable is saved.

Josher’s picture

Getting somewhere now.

Message: (#200) This API call requires a valid app_id.
Type: :OAuthException
Code: 200
User: :uid
milos.kroulik’s picture

ShadowMonster, can you, please, create patch based on your fix in #8? I also experience error mentioned in #7.

Josher, were you able to solve the problem? Thanks.

goekhanc’s picture

I would appreciate a patch file, too.

but what i dont understand is, why this module does not depend on the fboauth module or the facebook rules module. i think the code from post #8 assumes both of them to be active, doesnt it?

Josher’s picture

Got caught up with a few other items. It was a bummer the code snippets didn't work for my set up.

webroru’s picture

ShadowMonster, can you, please, create patch based on your fix in #8?

webroru’s picture

I can post messages on the wall page as a user, but when I admin I can't.

ShadowMonster’s picture

sorry guys will try create patch on weekend - very busy all time :(

kika’s picture

Any update on this? Facebook Page Rules seems a great liteweight component, very much needed.

spaceboii’s picture

One aspect that haven't really commented is the fact that "http_build_query", used in "facebook_page_rules_post()" for data formatting has change since php 5.3..
Solves the trouble some would have with strange errors regardning incomplete data sent ...

http_build_query($array, '', '&');

Hopes this helps someone...

BManuel’s picture

Hey guys can someone please roll a patch for a working version, I am ready to chip in to get this done.
Thanks to anyone who takes up this challenge
BM

Pls’s picture

Priority: Normal » Critical
Status: Active » Needs review
StatusFileSize
new1.13 KB

I suspect that this problem is completely equal to facebook_rules modules issue.

Unfortunetely I don't have time to test my patch right now, but I'm pretty sure it will work. Any feedback appreciated!

BManuel’s picture

@Pls I just did the test and got same error

Message: (#200) This API call requires a valid app_id.
Type: :OAuthException
Code: 200
User: :uid
SEVERITY error

I know my app_id is correct and I even enabled/disabled fboauth to see if that would help.

Also I get a "Message: Type: :Code: User: :uid" error after saving the app_id/secret key

Message:
Type: :
Code:
User: :uid

Thanks so much for your time and like I said earlier I am willing to chip-in if that's what needed to get this module working properly.
Drupal needs a light weight way to communicated with FB.

BM

Pls’s picture

Status: Needs review » Needs work

@BManuel, thanks for testing patch. I will try to make another patch when I have time. Changing to needs work.

Dr_Whut’s picture

Ok so I got this working by tracing back up the processes. The problem as far as I can see was that did didn't like encoding the ?q= part of the redirect URL of the OAUTH post.

Specifically at line 56

function facebook_page_rules_get_code($app_id) {
  $redirect_url = $GLOBALS['base_url'] . '?q=' . 'facebook_page_rules';
  $query = array(
    'client_id' => $app_id,
        'redirect_uri' => $redirect_url,
        'scope' => 'publish_stream,manage_pages',
  );
  $url = url("https://www.facebook.com/dialog/oauth", array('query' => $query));
  dsm($url);
  drupal_goto($url);
}

I managed to get this working by hardcoding it to

function facebook_page_rules_get_code($app_id) {
  $redirect_url = $GLOBALS['base_url'] . '/facebook_page_rules';
  $query = array(
    'client_id' => $app_id,
        'redirect_uri' => $redirect_url,
        'scope' => 'publish_stream,manage_pages',
  );
  $url = url("https://www.facebook.com/dialog/oauth", array('query' => $query));
  dsm($url);
  drupal_goto($url);
}

This is obviously not a lasting fix, but it's a start.

Oh and in addition, the Undefined Index errors are coming from the watchdog functions.

BManuel’s picture

Hi,
I am still getting the same error after making the change. Can you pls attached a copy of your version of the module here. That will save many of us the trouble of trying to get it right.
Thanks
BM

Dr_Whut’s picture

Ok here it is in patch form.

Be aware that this is a messy hotfix and mainly to better explain what I did. I do not recommend just flat patching this.

icampana’s picture

Status: Needs work » Needs review
StatusFileSize
new1.19 KB

Here is the right fix, the problem was generated if you had clean urls as stated by Dr_Whut, the problem with hist patch on #24 is that if you ever disable clean_urls you would have to edit the module again, and besides it is not too "Drupalistic".

The right way is to use the url function, that way it handles the propper generation of the URL and facebook doesn't complain because the URL changed during the token exchange, no matter if you use clean urls or not.

The original code looked like this:
$redirect_url = $GLOBALS['base_url'] . '?q=' . 'facebook_page_rules';

And now it should remain as this:
$redirect_url = url('facebook_page_rules', array('absolute' => TRUE));

I'm also attaching a patch to make the change.

kirkcaraway’s picture

OK, I have applied the patches, and now the errors are gone. However, there are no posts showing up on the Facebook page, either.

The patch in #24 removed the Watchdog thing, so I'm not sure if the module is working, or if it's just not showing there is an error.

Anyone else get this to work?

Thanks.

Funkwarrior’s picture

#25 Work fine for me, thanks!

bsandor’s picture

Issue summary: View changes

deleted comment

mrpeanut’s picture

Tried the patch from #25 and it did not apply cleanly for me:

git apply -v facebook_page_rules-url_fix-1529064-25.patch
Checking patch sites/all/modules/facebook_page_rules/facebook_page_rules.module...
error: while searching for:
}

function facebook_page_rules_get_code($app_id) {
  $redirect_url = $GLOBALS['base_url'] . '?q=' . 'facebook_page_rules';
  $query = array(
    'client_id' => $app_id,
       'redirect_uri' => $redirect_url,

error: patch failed: sites/all/modules/facebook_page_rules/facebook_page_rules.module:54
error: sites/all/modules/facebook_page_rules/facebook_page_rules.module: patch does not apply

So I then manually replaced the two lines and I'm still getting the #200 error. Should those changes still be working?

Sherif Darwish’s picture

#25 worked for me and posted to facebook
The important point to consider is that you should visit admin/config/system/facebook_page_rules and write all the details then after clicking save you have to check that the below variables are set (using sql or php mysqmin)
select * from variable where name like 'facebook_page_rules%';
among the existing variables there should be facebook_page_rules_page_token and facebook_page_rules_user_token
if you found them then try posting again and see if it will work, if not then you have to check the watchdog to see what was the error in setting those up