Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please guide for the next step in XF2. #60

Open
rakeshmali opened this issue Jul 18, 2018 · 33 comments
Open

Please guide for the next step in XF2. #60

rakeshmali opened this issue Jul 18, 2018 · 33 comments
Assignees
Labels

Comments

@rakeshmali
Copy link

rakeshmali commented Jul 18, 2018

Trying to setup following for xf2.x - https://github.com/xfrocks/bdApi/tree/master/php_demo

Authentication successfully done. Getting following message "Obtained access token successfully!" and URLs with tokens.

Now don't know what to do next?
How can I post a thread into a specific forum?

I want to create a post into my XF forum using the api.

I have tried like following but no success - https://domain.com/xf-php-api/index.php?action=request&url=https://forum.domain.com/community/api/index.php?users/me/timeline&oauth_token=TOKEN_CODE&access_token=TOKEN&forum_id=18&thread_title=Thread_Title&post_body=Description

You help will be much appreciated.

@daohoangson
Copy link
Contributor

Once you have got your token, it's quite straight forward:

  1. Find the api action you want to do in the doc https://github.com/xfrocks/bdApi/blob/master/docs/api.markdown
  2. Make request with a valid token and required parameters

If you want to create a new thread in a forum, use this https://github.com/xfrocks/bdApi/blob/master/docs/api.markdown#post-threads. The 3 required parameters are forum_id, thread_title and post_body. Something like this should work:

curl http://forum.domain.com/community/api/index.php?threads -d 'oauth_token=xxx&forum_id=2&thread_title=Thread+from+api&post_body=Hello+World!'

@daohoangson daohoangson self-assigned this Jul 19, 2018
@daohoangson
Copy link
Contributor

By the way, the XenForo 2 version doesn't support creating new thread yet but eventually it will. Both versions (XF1 and XF2) uses the same URL and parameters structure.

@rakeshmali
Copy link
Author

When I am hitting following command using terminal with proper oauth_token -

curl http://forum.domain.com/community/api/index.php?threads -d 'oauth_token=xxx&forum_id=2&thread_title=Thread+from+api&post_body=Hello+World!'

it is showing me following error -

{"status":"error","errors":["The requested page could not be found."],"system_info":{"time":1531974610,"visitor_id":1}}

  1. Is the above error due to "not supporting create new thread" feature by XF2(as you told in your last comment) or the error is something else?

  2. I know you are not the right person to ask this question but still if you have in your knowledge, could you please know me when XF2 can provide such option of create new thread using any api?

  3. Do you know any other way I can create thread in xf2 with API?

@daohoangson
Copy link
Contributor

  1. That is correct. If you are using the XF2 version of this add-on then POST /threads is not yet implemented. In the meantime, you can test with XF1, the api actions are the same.
  2. XenForo itself does not expose an api, everything mentioned here is implemented in the add-on. We plan to implement POST /threads in the next week.
  3. There is none that we know about.

@rakeshmali
Copy link
Author

1, 3 Thanks for the confirmation.

2 - Oh really.. That's great to know. Please add the email [email protected] into you newsletter or subscriber list so I can get notified about this update. Actually I really required this API option for my forum.

@daohoangson
Copy link
Contributor

I know it's a bit noisy but you can subscribe to this PR #40 to keep track of the api actions for XF2 implementations. I'll close this issue for now.

Cheers.

@rakeshmali
Copy link
Author

@daohoangson Having one more query, so opening it again.

I am able to create thread in xf2 using API. Thank you!

Having one more query - Is if possible to create an oauth token which never expire?

Right now, I am doing like this -

  1. Generated a api key and secrete key.
  2. setup a oauth_token using above keys
  3. Now, I have created a php (do.php) page where I collect oauth_token, forum_id, thread_title, post_body, thread_tags like -
    http://domain.com/do.php?oauth_token=xxx&forum_id=2&thread_title=Thread+title&post_body=Hello+World&thread_tags=test
    (Actually I will hit the above url with parameters from some other domain).
  4. And then in (do.php), I send the above data with curl request to the xenforo forum website, where I have authenticated.

But the oauth_token expire in few time. and everytime I need to create it again.

  1. So is it possible to create a never expiration validity token?
  2. If possible, Please correct me if my followed approach not the right way to do this action.

@daohoangson
Copy link
Contributor

daohoangson commented Aug 2, 2018 via email

@rakeshmali
Copy link
Author

Sorry, But I didn't get it. Which database you are talking about? Do I need to change in any db file?

@daohoangson
Copy link
Contributor

Sorry for not being clear.

You can change XenForo database, table xf_bdapi_token. Edit expire_date to some far away date.

@rakeshmali
Copy link
Author

Great!
Thank you so much for the quick response.

I will change it.

@rakeshmali
Copy link
Author

Hi @daohoangson ,
Opening the thread again.
I am still at the same api version as we discussed before.
I am tring to access the api. While I click on the link in "Authorization (step 1)", it redict me to the domiain which I have configured. And as I login, getting the following error on the page "bdapi_oauth2_error_invalid_client".

Could you please guide me to resolve the error.

I will then upgrade to the latest version of the [bd] api

@daohoangson
Copy link
Contributor

It stopped working suddenly?

@rakeshmali
Copy link
Author

Yes, Actually I have setup it before in working stage. And now I want to use it. Nothing changed but it is showing me this error.

@rakeshmali
Copy link
Author

rakeshmali commented Apr 17, 2019

should I update it to latest version and then test it again?

If yes then I will replace the 'api' and Xfrock(into src folder). and found the new JS folder. should I add the js folder into xf root folder's js directory?

@daohoangson
Copy link
Contributor

Yes, please upgrade to the latest version provided here https://xfrocks.com/resources/bd-api-for-xenforo-2-0.36/

@rakeshmali
Copy link
Author

@daohoangson, I am getting fatal error after upgrade to latest version.
FYI I have replaced api folder and src/addons folder with respective files and added js/Xfrocks in 'js' folder at root of website.

Fatal error: Uncaught InvalidArgumentException: Container key 'api.server' was not found in /var/www/website/community/src/XF/Container.php:43 Stack trace: #0 /var/www/website/community/src/XF/App.php(2758): XF\Container->offsetGet('api.server') #1 /var/www/website/community/src/addons/Xfrocks/Api/App.php(77): XF\App->container('api.server') #2 /var/www/website/community/src/XF/Container.php(28): Xfrocks\Api\App->Xfrocks\Api{closure}(Object(XF\Container)) #3 /var/www/website/community/src/XF/App.php(2040): XF\Container->offsetGet('request') #4 /var/www/website/community/src/XF/Error.php(264): XF\App->request() #5 /var/www/website/community/src/XF/Error.php(218): XF\Error->getExceptionTraceHtml(Object(InvalidArgumentException)) #6 /var/www/website/community/src/XF/App.php(1947): XF\Error->displayFatalExceptionMessage(Object(InvalidArgumentException)) #7 /var/www/website/community/src/XF.php(146): XF\App->displayFatalExceptionMessage(Object(InvalidArgumentException)) #8 [internal function]: XF::handleException(Object(InvalidArgumentException)) #9 {main} thrown in /var/www/website/community/src/XF/Container.php on line 43

Please help and suggest

@daohoangson
Copy link
Contributor

Have you upgraded the add-on in AdminCP?

@rakeshmali
Copy link
Author

Yes, Forgot to upgrade in admin.
I have upgraded it, that fatal error has been gone, but now I am getting the error of "Invalid client." as I login with admin user access.

@daohoangson
Copy link
Contributor

That error message means your client id/secret pair is not correct. Can you double check those?

Also, is your test site accessible on the Internet? I will come by and try it myself.

@rakeshmali
Copy link
Author

Okay. For website access detials, do I send at your email [email protected]?

@rakeshmali
Copy link
Author

@daohoangson Could you please confirm your email address so where I do sent you the access detials of my website?
Actaully I want to start this API posting ASAP, And I will really appriciate if you can provide me some help to start it.

@daohoangson
Copy link
Contributor

@rakeshmali that's my email. Thank you.

@rakeshmali
Copy link
Author

@daohoangson I have sent you the detials at your email address. Please check and suggrest.

@daohoangson
Copy link
Contributor

I have received your info. Let's continue over email.

@zernyu
Copy link

zernyu commented Nov 19, 2019

@daohoangson Not enough permissions to post comments in the XFRocks site for some reason so posting here... I have been successfully using this plugin on my XF2.1 setup for months, but now I am trying to get it setup on another forum and am running into authentication issues:

I am able to successfully create an auth token via OAuth2, however, when I then try to use the token, I get the following error:

curl -XGET -H "Authorization: Bearer THE_AUTH_TOKEN" "https://XFSITE/api/index.php?users/me"
{
    "status": "error",
    "errors": [
        "You must be logged-in to do that."
    ],
    "system_info": {
        "debug_url": "https:\/\/XFSITE\/api\/index.php?users\/me&_debug=1"
    }
}

I have tried on both a regular user and an admin user, both marked as Registered. The only differences between the previous forum and this forum are:

  • Previous Forum (bdApi works): XF 2.1.0, running behind http
  • New Forum (bdApi unable to authenticate): XF 2.1.3, running behind https

Any ideas what could be happening here? Thank you for all your work!

@daohoangson
Copy link
Contributor

Have you tried using oauth_token query param?

@zernyu
Copy link

zernyu commented Nov 19, 2019

Edit: created a new token and now it's working with the oauth_token query param.

How come I have to use the query param on this install and I can use the Authorization header in my other forum install?

@daohoangson
Copy link
Contributor

How come I have to use the query param on this install and I can use the Authorization header in my other forum install?

Probably some issue with the web server setup. Maybe your proxy (or similar software) truncated the auth header for security reason. It happens sometimes.

@zernyu
Copy link

zernyu commented Nov 20, 2019

BINGO! I did not think that the headers could be getting stripped. Another difference between the two installs is that the working server is behind nginx and the non-working server is behind apache. Solution here: https://stackoverflow.com/questions/26475885/authorization-header-missing-in-php-post-request

Thanks for pointing me in the right direction... 2 days of headaches resolved 😵

@daohoangson
Copy link
Contributor

Thanks for the Stack Overflow link, I didn't know Apache strips that header by default 😨

@CheckMater
Copy link

For people who is also having the Fatal error: Uncaught InvalidArgumentException: Container key 'api.server' was not found

In my case upgrading didn't work so just enable development mode in the forum config file:

$config['development']['enabled'] = true;

Then go to admin.php?code-events/listeners/ search the BD API app_setup event code listener and change the callback execution order to 9 or less

@daohoangson
Copy link
Contributor

That's weird. Sounds like a conflict with some other add-on. Do you mind opening another issue to further debugging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants