SMF 2.0 "REST" API

Started by Andre N, November 10, 2011, 09:29:31 PM

Previous topic - Next topic

Sunchaser

Quote from: Kindred on October 02, 2013, 11:53:38 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.

Arantor

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.

Kindred

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.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sunchaser

Quotewhen 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.

QuoteIf 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.



Kindred

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.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sunchaser

Quote from: Kindred 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()?

yes

koma

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?

koma

#67
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,

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'])) {

Akiracr

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 protected]');
$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

spyphone2015

#69
Thanks share for me. i also error : Unknown method sitename_smf_api_login_user was called. please help me

matt.ernst

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).

xeon365

Quote from: matt.ernst 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).


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.

codeforgood

Quote from: Andre N on January 12, 2012, 01:05:06 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

z1haze

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?

Kindred

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.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

z1haze

Quote from: Kindred 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...

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 protected] [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 hxxp:mysite.com/api/ [nonactive]...

Kindred

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.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

z1haze

I've not been aple to send the activation email to the user when adding members with the smf_2_api.php

z1haze

If anyone knows how to send the activation email via the SMF api or the REST api please let me know.

bo100nka

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?

Advertisement: