Error opening Open Open code on Facebook

I figured it out for ages, there is no debugging tool or in the terminal console, but it continues to pop up an β€œerror” in the following codes:

<script type="text/javascript"> function postCook() { $pageURL = window.location; FB.api('/me/bgfapp:watch?movie=' + $pageURL,'post', function(response) { if (!response || response.error) { alert('Error Occurred'); } else { alert('Post was successful! Action ID: ' + response.id); } }); } </script> 

I tried to display $ pageURL and it successfully returns the current URL, so I cannot figure out what is wrong with the above code.


updated: 30-Jan-2012

the error says: An error has occurred [object Object] [object Object]

+4
source share
2 answers

You may have already found a solution, but hopefully this helps someone else.

The problem is that you do not know the names of the child nodes in the response object. If you cannot name a specific node, then you will constantly receive this error message: "An error has occurred [Message of object of object]”

I have a workaround that will allow you to see the error message without knowing the names of the child nodes of the response object. JSON.stringify simply converts the entire object to a string, allowing you to view its contents. It will not be very good, but you will definitely see an error message.

Try the following:

 <script type="text/javascript"> function postCook() { $pageURL = window.location; FB.api('/me/bgfapp:watch?movie=' + $pageURL,'post', function(response) { if (!response || response.error) { alert(JSON.stringify(response)); } else { alert('Post was successful! Action ID: ' + response.id); } }); } 

An alternative solution would be to output the contents of the response object to the console, rather than executing a warning, just replace line 7 in my code example as follows:

 console.log(response); 

Here you can open the development console of your web browser and go through the contents of the response object. Since the console is not always available (for example, applications with telephone recordings), the previous solution is sometimes more suitable.

+1
source

Based on your new error message, it looks like you need to look at what response.error says. Your logic says that either you don’t have an answer at all, or you have a response.error . First you must find out in which case you are and act accordingly.

response.responseText and response.error.responseText are undefined because they are not returned to you.

  $pageURL = '/me/bgfapp:watch?movie=' + window.location; FB.api($pageURL,'post', function(response) { if (!response) { alert('Error Occurred I got no response with ' + $pageURL); } else if (response.error) { alert('Error Occurred '+ response.error); } else { alert('Post was successful! Action ID: ' + response.id); } }); 

My suggestion is to try the simple one and make your way. Debug all the variables you are checking. If you do not receive a response, it may be that your final API call does not exist. If you receive an error message, your call is incorrect or may not be authenticated.

0
source

Source: https://habr.com/ru/post/1393587/


All Articles