M
M
Mega_User2015-06-25 18:08:12
JavaScript
Mega_User, 2015-06-25 18:08:12

How to fix weird error while initializing api?

There is an application for classmates, the start page of which (opens in a frame) is a page with an address of the form site.ru/app/index.php. When it is opened, the api is initialized and it is used to call users.getCurrentUser. Everything works fine, api returns correct data.
But if you follow the link located in the application itself (to the same address of the application page), then an error appears when initializing the api Uncaught TypeError: Cannot read property 'indexOf' of undefined (fapi5.js: 1) I
connect and initialize the api like this:

<script type="text/javascript" src="http://api.odnoklassniki.ru/js/fapi5.js"></script>

var rParams = FAPI.Util.getRequestParameters();
FAPI.init(rParams["api_server"], rParams["apiconnection"],  
    function() {
        console.log("ok");
    },   
    function(error){
        console.log("error");
    }
);

Please advise how to fix this error.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Rytikov, 2015-06-25
@Mega_User

The problem is that FAPI.Util.getRequestParameters() returns an empty array. This function returns values ​​based on GET parameters in the address bar. Pay attention to what goes on the site.ru/app/index.php page after the "?" (for example, ?pageId=42476523). All internal pages in the frame must also contain these parameters.

C
cheplv, 2015-06-26
@cheplv

This problem appears when the user enters the application through the version for mobile applications (m.ok.ru). fapi5.js does not receive the web_server parameter. Looking deeper, for the mobile version, fapi5.js can only be used for REST calls.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question