Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Oauth签名,RESTAPI_Php_Api_Oauth - Fatal编程技术网

Php Oauth签名,RESTAPI

Php Oauth签名,RESTAPI,php,api,oauth,Php,Api,Oauth,我正在尝试访问fat秘密API 我正在尝试使用fat secret提供的密钥创建Oauth签名。当我试图访问URL来获取数据时,我得到一个错误,说我的Oauth签名无效 我使用base64_编码创建签名,然后使用sha1散列hmac 这是我的密码,我的密钥被屏蔽了,我是不是用错误的方式创建了签名?或者有人能看出我哪里做错了 多谢各位 <?php $requestTokenUrl = "http://platform.fatsecret.com/rest/server.api"; $oau

我正在尝试访问fat秘密API

我正在尝试使用fat secret提供的密钥创建Oauth签名。当我试图访问URL来获取数据时,我得到一个错误,说我的Oauth签名无效

我使用base64_编码创建签名,然后使用sha1散列hmac

这是我的密码,我的密钥被屏蔽了,我是不是用错误的方式创建了签名?或者有人能看出我哪里做错了

多谢各位

<?php
$requestTokenUrl = "http://platform.fatsecret.com/rest/server.api";
$oauth_consumer_key = "925f5e1a8b674a70b52eabf15f3265e7"; 
$nonce = md5(mt_rand());
$outh_signature = '';
$oauthSignatureMethod = "HMAC-SHA1"; 
$oauthTimestamp = time();
$oauthVersion = "1.0";
$secret_key = "My Secret Key";

$sigKey= $consumer_key . "&";

$sigBase = "method=food.get" . rawurlencode($requestTokenUrl) . "&"
    . rawurlencode("oauth_consumer_key=" . rawurlencode($oauth_consumer_key)
    . "&oauth_nonce=" . rawurlencode($nonce)
    . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
    . "&oauth_timestamp=" . $oauthTimestamp
    . "&oauth_version=" . $oauthVersion);

$oauthSig = base64_encode(hash_hmac('sha1', $secret_key, true));

$requestUrl = $requestTokenUrl . "?"
    . "food_id=33691"
    . "&method=food.get"
    . "&oauth_consumer_key=" . rawurlencode($oauth_consumer_key)
    . "&oauth_nonce=" . rawurlencode($nonce)
    . "&oauth_signature=" . rawurlencode($oauthSig)
    . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
    . "&oauth_timestamp=" . rawurlencode($oauthTimestamp)
    . "&oauth_version=" . rawurlencode($oauthVersion);

var_dump($requestUrl);

我认为您的签名库缺少您在请求中传递的food_id参数。我总是发现使用谷歌的这个工具来测试我生成的代码的签名是否与预期的签名匹配是很有帮助的:事实上,看起来你并没有用$sigBase做任何事情,而且它缺少一些部分。请参阅OAuth 1.0a标准以查看所有部件及其构造方式:。构建签名库后,使用
hmac\u散列('sha1',$sigBase,$secret\u key)
使用密钥对签名库进行签名。我认为不需要base64编码,只需要哈希,除非fatsecret需要。我认为您的签名库缺少您在请求中传递的food_id参数。我总是发现使用谷歌的这个工具来测试我生成的代码的签名是否与预期的签名匹配是很有帮助的:事实上,看起来你并没有用$sigBase做任何事情,而且它缺少一些部分。请参阅OAuth 1.0a标准以查看所有部件及其构造方式:。构建签名库后,使用
hmac\u散列('sha1',$sigBase,$secret\u key)
使用密钥对签名库进行签名。我认为不需要base64编码,只需要散列,除非fatsecret需要它。