dongyuntao2000 2015-07-20 13:03
浏览 49
已采纳

change.org登录API调用

I have done few API calls to change.org API and got user profile details and user created petition list, now i need to find a way to sign in using the API. but i am unable to figure why its not working.

This is the code to get the list of petition

<?php
$API_KEY = '32cf9810f982f95613cec5cce3154dc83966f2a89111661e6355938ad70b20f6';
$REQUEST_URL = 'https://api.change.org/v1/users/325635554/petitions';
//$PETITION_URL = 'https://www.change.org/p/kasun-pay-your-workers-overtime';
$parameters = array(
    'api_key' => $API_KEY,
    //'petition_url' => $PETITION_URL
);
$query_string = http_build_query($parameters);
$final_request_url = "$REQUEST_URL?$query_string";
$response = file_get_contents($final_request_url);
$json_response = json_decode($response, true);

echo $response; exit;
?>

Response

{
  "page": 1,
  "prev_page_endpoint": null,
  "next_page_endpoint": null,
  "total_pages": 1,
  "petitions": [
    {
      "petition_id": 3777680,
      "title": "kosala: Pay your workers salary",
      "status": "open",
      "url": "",
      "overview": "Pay your workers salary",
      "targets": [
        {
          "name": "kosala",
          "type": "custom"
        }
      ],
      "letter_body": "Pay your workers salary",
      "signature_count": 1,
      "image_url": "",
      "category": null,
      "goal": 100,
      "created_at": "2015-07-20T11:51:56Z",
      "end_at": "2016-07-20T23:59:59Z",
      "creator_name": "Amarn Dev",
      "creator_url": "https:",
      "organization_name": null,
      "organization_url": null
    },
    {
      "petition_id": 3776824,
      "title": "kasun: Pay your workers overtime",
      "status": "open",
      "url": "https:",
      "overview": "Pay your workers overtime Pay your workers overtime",
      "targets": [
        {
          "name": "kasun",
          "type": "custom"
        }
      ],
      "letter_body": "Pay your workers overtime",
      "signature_count": 1,
      "image_url": "",
      "category": null,
      "goal": 100,
      "created_at": "2015-07-20T08:52:10Z",
      "end_at": "2016-07-20T23:59:59Z",
      "creator_name": "Amarn Dev",
      "creator_url": "https://api.change.org/u/325635554",
      "organization_name": null,
      "organization_url": null
    },
    {
      "petition_id": 3623702,
      "title": "Jon Tester: Pay your workers overtime",
      "status": "open",
      "url": "https://api.change.org/p/jon-tester-pay-your-workers-overtime",
      "overview": "Pay your workers overtime",
      "targets": [
        {
          "name": "Sen. Jon Tester, Montana",
          "title": "Senator",
          "type": "us_government",
          "target_area": "Montana"
        }
      ],
      "letter_body": "Pay your workers overtime",
      "signature_count": 1,
      "image_url": "//d22r54gnmuhwmk.cloudfront.net/app-assets/petitions/show/default_petition-8290d88b72fb74c3e759135dcbc48b22.png",
      "category": null,
      "goal": 100,
      "created_at": "2015-06-22T06:38:59Z",
      "end_at": "2016-06-22T23:59:59Z",
      "creator_name": "Amarn Dev",
      "creator_url": "https://api.change.org/u/325635554",
      "organization_name": null,
      "organization_url": null
    }
  ]
}

Now to sign in they have given this API doc. https://github.com/change/api_docs/blob/master/v1/documentation/resources/petitions/signatures.md#post-signatures

auth_key    string  The petition authorization key.

so when i make a request to this URL

https://api.change.org/v1/petitions/3623702/signatures

with post params

api_key=32cf9810f982f95613cec5cce3154dc83966f2a89111661e6355938ad70b20f6&lastName=Hello&email=hello123%40gmail.com&firstName=World&city=Chennai&postal_code=00200&country_code=IN

i am getting this error.

{"result":"failure","messages":["authorization key cannot be found or is not granted"]}

API Key 32cf9810f982f95613cec5cce3154dc83966f2a89111661e6355938ad70b20f6

Secret 6acc5384782f8449e2775c3abf7688ec89cfa1ac76c710f2a745ad5c323e5bc9

  • 写回答

1条回答 默认 最新

  • douren6035 2015-12-13 05:17
    关注

    you need to send a rsig variable

    $parameters['rsig'] = hash('sha256', $query_string_with_secret_and_auth_key);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 MATLAB APP 制作出现问题
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e
  • ¥15 使用deepspeed训练,发现想要训练的参数没有梯度
  • ¥15 寻找一块做为智能割草机的驱动板(标签-stm32|关键词-m3)
  • ¥15 信息管理系统的查找和排序
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),怎么用读取的电磁传感器信号表示小车所在的位置
  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。