Advertisement:

Author Topic: SMF 2.0 "REST" API  (Read 184441 times)

Offline Sunchaser

  • Semi-Newbie
  • *
  • Posts: 41
Re: SMF 2.0 "REST" API
« Reply #60 on: October 02, 2013, 11:58:10 AM »
read the wiki?

http://wiki.simplemachines.org/smf/Category:Integrating_SMF

Thank you. If i understood well, if for example I have a Forum board Kingdom of London and i want that the board can be accessed ONLY if the player is actually located in London in the game, I need to use the Integration Hooks.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,392
    • StoryBB/StoryBB on GitHub
Re: SMF 2.0 "REST" API
« Reply #61 on: October 02, 2013, 12:01:24 PM »
That's a much, much more complex task than any use of APIs will be because it's not how SMF is designed to work.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,429
  • Gender: Male
    • Kindred-999 on GitHub
Re: SMF 2.0 "REST" API
« Reply #62 on: October 02, 2013, 12:02:43 PM »
when you say "board" do you actually mean board in the SMF sense... e.g. one of the things listed on your board index that holds the message threads?

If so, then you just need to place the user in a membergroup called "london" and give that group access to the board.

If you need to read the user's location real-time and determine their access (add or remove access) based on realtime data, then you are talkign about writing something from scratch that is not currently handled by ANY system in SMF, API, hooks or SSI.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Sunchaser

  • Semi-Newbie
  • *
  • Posts: 41
Re: SMF 2.0 "REST" API
« Reply #63 on: October 02, 2013, 12:07:23 PM »
Quote
when you say "board" do you actually mean board in the SMF sense... e.g. one of the things listed on your board index that holds the message threads?

Yes.

Quote
If you need to read the user's location real-time and determine their access (add or remove access) based on realtime data, then you are talkign about writing something from scratch that is not currently handled by ANY system in SMF, API, hooks or SSI

Ok, _I_think_ I can solve it in another way:

1) I use SSI.php to show the London Board content in a page available only in the Kingdom of London;
2) I use the API to let only Kingdom of London citizens post in that board.



Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,429
  • Gender: Male
    • Kindred-999 on GitHub
Re: SMF 2.0 "REST" API
« Reply #64 on: October 02, 2013, 12:16:47 PM »
or you can just collect the post in a form and use the standard SMF function create_post()?
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Sunchaser

  • Semi-Newbie
  • *
  • Posts: 41
Re: SMF 2.0 "REST" API
« Reply #65 on: October 02, 2013, 12:21:58 PM »
or you can just collect the post in a form and use the standard SMF function create_post()?

yes

Offline koma

  • Newbie
  • *
  • Posts: 2
Re: SMF 2.0 "REST" API
« Reply #66 on: January 21, 2014, 05:08:23 AM »
Is there a possibility to modify post with the api? I tried to search for that, but couldn't. Any change for getting that possibly in hte future?

Offline koma

  • Newbie
  • *
  • Posts: 2
Re: SMF 2.0 "REST" API
« Reply #67 on: February 14, 2014, 02:13:13 AM »
Hi, I've been trying to implement this rest API, and ran into, trouble. I tried to get the posterdata from get?userinfo *or what it was( function, seems like it doesn't return array (or decent json object) but a string presentation of the array dump. Is this intented?

and I think I found a slight bug in SmfRestServer.php,
Code: [Select]
on line 375
is:
if (!isset($topicOptions['board']) || !isset($msgOptions['subject']) || !isset($msgOptions['body'])) {

it should be (I believe):
if (!isset($this->topicOptions['board']) || !isset($this->msgOptions['subject']) || !isset($this->msgOptions['body'])) {
« Last Edit: February 14, 2014, 02:26:38 AM by koma »

Offline Akiracr

  • Newbie
  • *
  • Posts: 1
Re: SMF 2.0 "REST" API
« Reply #68 on: March 29, 2014, 12:12:59 AM »
Hi,

I tray to implement the REST API solution, my code is as follows:

 $api = new SmfRestClient(SMF_INTEGRATION_KEY);
 $login = $api->login_user('email@domain.net');
 $result = $api->get_userInfo();


I test the login and return true but when dump the $result variable return this:


stdClass Object
(
    [data] => stdClass Object
        (
            [groups] => Array
                (
                   
  • => -1

                )

            [possibly_robot] =>
            [id] => 0
            [username] =>
            [name] =>
            [email] =>
            [passwd] =>
            [language] => english
            [is_guest] => 1
            [is_admin] =>
            [theme] => 0
            [last_login] => 0
            [ip] => 127.0.0.1
            [ip2] =>
            [posts] => 0
            [time_format] => %B %d, %Y, %I:%M:%S %p
            [time_offset] => 0
            [avatar] => stdClass Object
                (
                    [url] =>
                    [filename] =>
                    [custom_dir] =>
                    [id_attach] => 0
                )

            [smiley_set] =>
            [messages] => 0
            [unread_messages] => 0
            [total_time_logged_in] => 0
            [buddies] => Array
                (
                )

            [ignoreboards] => Array
                (
                )

            [ignoreusers] => Array
                (
                )

            [warning] => 0
            [permissions] => Array
                (
                )

        )

    [error] =>
)


I don't understand what happened, why don't return the user information, someone has an idea why this can happen.


Thanks for the help

Offline spyphone2015

  • Newbie
  • *
  • Posts: 1
Re: SMF 2.0 "REST" API
« Reply #69 on: April 07, 2014, 11:06:46 PM »
Thanks share for me. i also error : Unknown method sitename_smf_api_login_user was called. please help me
« Last Edit: April 07, 2014, 11:57:18 PM by spyphone2015 »

Offline matt.ernst

  • Newbie
  • *
  • Posts: 1
Re: SMF 2.0 "REST" API
« Reply #70 on: May 06, 2014, 01:50:40 AM »
Akiracer, koma, you are both getting the "raw" formatted data instead of JSON data. I had the same problem. I thought maybe it was because I'm using a less-common setup (nginx and php5-fpm). I didn't bother to figure out where the logic was going wrong. I just changed line 186 of SmfRestServer.php to replace 'raw' with 'json'. I'm always going to be using the JSON calls so I didn't care about fixing the detection logic.

I also had to convert the .htaccess rewrite rule to the nginx equivalent, in case anyone else is trying to do the same.

At the end of the server block for your SMF installation, put

location /api {
  rewrite .* /api/index.php last;
}

(of course replacing /api with your actual installation directory, if you have changed it).

Offline xeon365

  • Semi-Newbie
  • *
  • Posts: 29
Re: SMF 2.0 "REST" API
« Reply #71 on: November 11, 2014, 09:59:25 AM »
Akiracer, koma, you are both getting the "raw" formatted data instead of JSON data. I had the same problem. I thought maybe it was because I'm using a less-common setup (nginx and php5-fpm). I didn't bother to figure out where the logic was going wrong. I just changed line 186 of SmfRestServer.php to replace 'raw' with 'json'. I'm always going to be using the JSON calls so I didn't care about fixing the detection logic.

I also had to convert the .htaccess rewrite rule to the nginx equivalent, in case anyone else is trying to do the same.

At the end of the server block for your SMF installation, put

location /api {
  rewrite .* /api/index.php last;
}

(of course replacing /api with your actual installation directory, if you have changed it).


good fix... what a head bang that was.. thought I had forgotten how to use php arrays, the return was just a string that looked like a array or object.

Offline codeforgood

  • Newbie
  • *
  • Posts: 1
Re: SMF 2.0 "REST" API
« Reply #72 on: February 11, 2015, 07:50:44 PM »
If that is not an option, you might be able to trick SMF into setting the cookie (or deleting it) locally by using cURL to send the login information to your SMF login address. That is the method used by JFusion and seems like it would work , however I haven't had any success doing it yet.
The idea would be to take your SMF login location /index.php?action=login2
and cURL the post data, username and password to it and the cookie should be set by SMF.
It would be a nice feature to have and I'll play with it when I get a chance, but if you have any success please post back :)

Interesting idea, have you tested this approach?

I have the same requirement. I'm looking to create a not-for-profit sports club fan app that integrates multiple communication channels into one. This will give our team's fans a central place to stay up to date / discuss their team. One of the source channels is a SMF forum which i don't manage. I'd like to consume the SMF posts via an API that i will develop, hence my initial question.

Any feedback / ideas would be really appreciated. I'm new to SMF.

Thanks

Offline z1haze

  • Newbie
  • *
  • Posts: 4
Re: SMF 2.0 "REST" API
« Reply #73 on: July 17, 2015, 03:10:45 PM »
I may be grave digging, so excuse me but I am a brand new user to the SMF community. I was just wondering is this REST api still functional, and is it the most current RESTful api available for SMF?

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,429
  • Gender: Male
    • Kindred-999 on GitHub
Re: SMF 2.0 "REST" API
« Reply #74 on: July 17, 2015, 03:21:24 PM »
well, nothing really has been done with it since it was created... but the backing system has not changed significantly since its creation, either...
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline z1haze

  • Newbie
  • *
  • Posts: 4
Re: SMF 2.0 "REST" API
« Reply #75 on: July 17, 2015, 03:50:03 PM »
well, nothing really has been done with it since it was created... but the backing system has not changed significantly since its creation, either...

Can you help me with using it briefly? I am coming from XenForo which has similar API that I use to register new members via inside a game from a plugin that basically calls hxxp:mysite.com/api.php?action=register&key=mykey&username=username&email=email@email.com [nonactive] etc etc

With this I can add new users to my database safely and easily. How can I do that with this api? Would I have to basically write my own file that implements this api or can I just do it straight from mysite.com/api/...

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 58,429
  • Gender: Male
    • Kindred-999 on GitHub
Re: SMF 2.0 "REST" API
« Reply #76 on: July 17, 2015, 05:24:06 PM »
I believe that you have to rite your own file that calls functions from the API...   but the first post in this thread... and the wiki section on integrating SMF should have more explanation
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline z1haze

  • Newbie
  • *
  • Posts: 4
Re: SMF 2.0 "REST" API
« Reply #77 on: July 17, 2015, 09:23:23 PM »
I've not been aple to send the activation email to the user when adding members with the smf_2_api.php

Offline z1haze

  • Newbie
  • *
  • Posts: 4
Re: SMF 2.0 "REST" API
« Reply #78 on: July 18, 2015, 11:50:24 AM »
If anyone knows how to send the activation email via the SMF api or the REST api please let me know.

Offline bo100nka

  • Newbie
  • *
  • Posts: 1
Re: SMF 2.0 "REST" API
« Reply #79 on: December 11, 2015, 12:55:44 PM »
hey guys,
when i try to send pm using send pm or show logout link functions and then print_r it i get this strange error:
Try again, the settings path should be saved now.

any idea what could have i done wrong?