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

Angular2: The NgFor directive is designed to work with Iterables like Arrays for data binding

I'm currently working on a university project to develop a web application consisting of a Web API and a Frontend that interacts with the API. The specific focus of this project is a recipe website. Although I have limited experience with technologies ...

Retrieving JSON data in Perl

Struggling with accessing json values (translated from xml). foreach my $PORT (0..$#PORTS) { print Dumper $PORTS[$PORT]->{'neighbor'}; if (defined($PORTS[$PORT]->{'neighbor'}->{'wwn'}->{'$t'})) ...

Is there a way to include a React component within the setContent method of Leaflet?

Is there a way to trigger a React JS component in setContent? I am looking for a solution to add a button within a popup Leaflet, which when clicked will call a React component. While I am aware of the "reactDomserver.rendertostring" method to co ...

Changing the shape of a background using CSS when hovering

My Bootstrap navigation has a unique setup, as shown below. I've observed that many users tend to only interact with the headings and ignore the submenus where the actual products are located. To address this issue, I want to change the design of th ...

Mastering the extraction of key/value pairs from a JSON response in the OnComplete ajax

After executing a specific action, it is returning the following outcome: return Json(new { result = true, value = "hello" }, "text/html"); I'm wondering how can I retrieve the value in my onComplete function? onComplete: function (file, respo ...

Can you explain the significance of this async JavaScript server application error?

While working on a weather app website connected to another site through a server, I encountered an issue with asynchronous JavaScript. Upon running the code, I received an error message stating "uncaught syntax error: unexpected end of input" in the last ...

Mandating the inclusion of a directives controller in conjunction with other necessary controllers

Two directives are nested within each other, with one requiring the other using require: '^parentTag' . Both directives have their own controllers. In the parent directive, I can access its controller as the fourth argument in link: function(scop ...

What Causes the "Do Not Push Route with Duplicated Key" Error in React Native with Redux?

I have successfully integrated Redux into my React Native project, specifically for navigation purposes. Below is the code snippet from my navigation reducer file (navReducer.js): import { PUSH_ROUTE, POP_ROUTE } from '../Constants/ActionTypes' ...

Format the date using moment() for the last week of the current year and return it with the year. Next year's

I encountered an unusual problem when using Moment.js with Angular.js. When I use the .toISOString() method, I get the correct date, but when I use the .format() method, the date is completely wrong. Here is an example to illustrate the issue: Code snip ...

Decoding structured data in Golang

While working on a golang struct that needs to be compatible with a specific JSON structure, most of the fields are known. However, there will be a few fields following certain patterns in the JSON definition (such as "x-{randomName}") that I also want to ...

Reorganizing Arrays in Javascript: A How-To Guide

I have an array in JavaScript called var rows. [ { email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="81f4f2e4f3b0c1e4f9e0ecf1ede4afe2eeec">[email protected]</a>' }, { email: '<a hre ...

What is the best way to compare two arrays in my JSON data?

Hello, I'm trying to compare two arrays - one from my JSON data and the second from a regular array. Specifically, I want to check if the ids of "cm:taggable" exist in my secondArray. JSON { "entry": { "isFile": true, "createdByUs ...

React - Updating the Color of a Specific Div within a Map Component

Currently, I am delving into React and Material UI and facing an issue with changing the background color of a clicked div. As it stands, all the divs are being affected when one is clicked. My goal is to have the background color transition from white to ...

Browsing through items within arrays to evaluate their values

I am facing an issue with two arrays that consist of objects. The first array contains restaurant objects with attributes such as name and averagePrice, while the second array has price objects (cheap, medium, expensive) with properties like label, lowEnd, ...

Issue with $watch function causing $scope variable to remain undefined, even though it is being explicitly

I've been encountering an issue while trying to insert data into my Firebase database using a user's uid. It seems to be coming out as undefined for some reason. Here's a closer look at the code snippet causing the problem: The primary cont ...

Can two different versions of a library be utilized simultaneously in NPM?

Currently, our Vue.js app is built with Vuetify v1.5 and we are considering transitioning to Vuetify 2.0. However, the process would involve numerous breaking changes which we currently do not have the resources to address for all components. Is there a wa ...

What is the reason the child component is not being displayed?

The code within the APP.js component looks like this: import React from "react"; import Exam from "./exam.js"; export default function App() { return ( <Exam> <h1>hashemi</h1> </Exam> ); } Similarly, the ...

Leveraging CasperJS in a typical JavaScript script

I am currently working on a NodeJS project that involves integrating CasperJS. However, I have encountered an issue where the 'casper' module cannot be located. In an attempt to resolve this, I decided to npm install spooky --save based on some s ...

I am currently facing an issue where the code provided in the Puppeteer documentation is not functioning correctly due to an Un

I followed the code example on the Puppeteer documentation website but unfortunately, it's not working for me. I have Puppeteer 3.0.0 installed via npm. const puppeteer = require('puppeteer'); (async () => { const browser = await pup ...

Deactivate the form fields using Ajax

Whenever I try to use this Ajax script for posting data and disablind the send-button along with all form fields, only the submit button gets disabled on click. What I actually want is to disable all the form fields as well. So, in order to achieve this, ...