Error message: Unauthorized request error with the change.org JavaScript API

I am currently working on integrating the javascript API from change.org in order to retrieve all of my signed petitions for display on my source forge page. However, I am encountering an unauthorized request response from the change.org API.

Despite trying various approaches such as using api_secret and secret parameters, I consistently receive the 'unauthorized request' message.

Any advice or suggestions would be greatly appreciated :)

The javascript code I am using is as follows:

<html>
<head>
<title>change.org test</title>
<script type="text/javascript" src="./sha256.js"></script>
<script type="text/javascript" src="./changeorgapi.js"></script>
<script type="text/javascript">
function getAllPetitions() {
var client  = new ChangeOrgApiClient({
"api_key" : "omitted for security",
"secret"  : "omitted for security"
});

var user = new ChangeOrgApiUser(client);

user.setCallback(function(response) {
alert("message: " + JSON.stringify(response.getData()));
});

user.getSignedPetitions({
"user_id" : 31368676,
"fields" : "title,url,signature_count",
"page_size" : 5,
"page" : 1,
"sort" : "signatures_asc"
});
}

getAllPetitions();
</script>
</head>
<body>change.org test</body>
</html>

Answer №1

Upon reviewing this tutorial, I followed these steps to successfully request access to the Change API:

1) Sign up on the platform.

2) Obtain the API key from your account page.

3) Create the request following the provided example:

Base URL: URL with parameters: .

4) Verify if the GET request to that URL functions correctly using curl.

5) Replicate my request from my JavaScript application (essentially copied the curl request from Chrome browser).

If everything progresses smoothly from steps 1 to 4, then the API is functioning appropriately with your credentials. If the process fails at step 4, there may be an issue with the URL or the credentials (Double check and retry).

Curl example:

curl ' -H 'accept-encoding: gzip, deflate, sdch' -H 'accept-language: en-US,en;q=0.8' -H 'user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36' -H 'accept: /' --compressed

Answer №2

Accessing petitions/:petition_id/signatures
is no longer supported, however you can still use
GET petitions/:petition_id/signatures/recent
to retrieve the most recent 10 signatures.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to include a CSS file path in a link tag from an npm package

I have recently installed a package using npm. npm install lightgallery Now, I am trying to fill the href attribute of a link with the css file directory of this package. Here is what I have so far: <link rel="stylesheet" href="/node_mod ...

Tips for labeling subplots in PLOTLY JS

Looking for some guidance on adding titles to plots in Plotly JS. I've checked out the documentation but couldn't find anything helpful. Any tips or suggestions would be greatly appreciated! ...

Change the class of <body> when the button is clicked

One of my tasks involves adding a button that, when clicked, should give the body the class "open-menu". Implementing this using jQuery was quite straightforward - I just needed to add the following line of code: $('.burger').click(function() ...

`Unexpected error occurred during JSON parsing due to a unrecognized selector being sent to the

Can someone assist me in debugging this piece of code? dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ NSError *error = nil; NSURL *urls = [NSURL URLWithString:[NSString stringWi ...

Using JSON parsing to dynamically create classes with preloaded background images

Today, I successfully deployed my browser game using MVC4 to my website for the first time. I am currently navigating through the differences between running the site off of localhost and running it from the actual website. My process involves loading all ...

Using RestSharp to convert a JSON string into an object

I have been struggling to deserialize the returned response.Content string without success. The WebApi action sends back a modified modelState with extra custom errors. On the MVC side, I attempted several methods but none of them were successful: JsonDe ...

The styles order definition in the Material-UI production build may vary from that in development

When using material-ui, an issue arises in the production build where the generated styles differ from those in development. The order of the material-ui styles in production does not match the order in development. In DEV, the material-ui styles are defi ...

Execute Cheerio selector once the page has finished loading

Hey there! I'm trying to extract the URL value of an iframe on this website: I've checked the view page source but couldn't find the iframe. Looks like it's loaded after the page is fully loaded through JavaScript. Could it be that ...

Get your hands on large files with ease by utilizing jQuery or exploring alternative methods

Within my User Interface, there exists an Advanced Search section where the user can select from 7 different options as depicted in the diagram. Based on these selections, a web service is triggered. This web service returns search results in JSON format, ...

What is the best way to link JavaScript files from a Grails plugin in a separate Grails application?

I have developed a unique plugin that offers multiple Grails controllers and domain objects. Additionally, I have created several AngularJS UI components that I wish to utilize in various other projects. These specific files are located within the web-app ...

Discovering the value of a chosen star and saving it in a database with the help of jQuery or JavaScript

When a user clicks on the 3rd star in the Jrate Plugin, I need to retrieve the value of 3. This can be achieved using the jRate onSet option. Below is my HTML: <div id="jRate"></div> And this is my JavaScript code: $("#jRate").jRate({ ...

Determining the moment a user exits a page on Next JS

Is there a way to track when the user exits a Next JS page? I have identified 3 possible ways in which a user might leave a page: Clicking on a link Performing an action that triggers router.back, router.push, etc... Closing the tab (i.e. when beforeunloa ...

Failed to fully install all dependencies for my project with yarn install

After cloning a project from gitlab, I attempted to install the dependencies using the yarn install command. However, there are several dependencies that yarn is unable to install and it keeps showing the error message: info There appears to be trouble wit ...

position: absolute is only applying to the initial item

I have a user card component with a menu button at the top that should display a menu when clicked. The issue I'm facing is that when I click on the menu button of the other user cards, the menu still shows on the first card instead of the one I click ...

What is the process for pausing a video while it is still buffering and loading?

Is it possible to suspend a video when it is in an opening or preparing state? For example, if I open a video and then switch to another application using the smart hub feature, how can I suspend the video while it is in the process of opening or preparin ...

Is it possible to assign a deconstructed array to a variable and then further deconstruct it?

Is there a way to deconstruct an array, assign it to a variable, and then pass the value to another deconstructed variable all in one line of code? Take a look at what I want to achieve below: const { prop } = [a] = chips.filter(x => x.id == 1); Typic ...

How can you decode JSON using JavaScript?

Need help with parsing a JSON string using JavaScript. The response looks like this: var data = '{"success":true,"number":2}'; Is there a way to extract the values success and number from this? ...

employing iframes dynamically to overlay a webpage

I inserted this iframe into a webpage <iframe src='http://redbug.redrocksoftware.com.au:80/Pages/chamara.html' style="position:absolute;z-index:1;" ></iframe> The chamara.html page has a button that, when clicked, should cover the c ...

Is there a way to use the onclick event to open a link in the same window and tab?

I am facing a challenge with a webpage containing multiple divs. I am trying to extract data from my database and display it within specific divs on the page. Additionally, I want this information to be presented when clicking on a link taking me back to t ...

Unable to transfer an array from getStaticProps method in Next.js

Whenever I pass a JSON array from getStaticProps in Next.js, I encounter this specific error message when trying to access it. TypeError: Cannot read property 'contentBody' of undefined module.exports../pages/[author]/[article].js.__webpack_expo ...