我正在尝试调用此API(Oauth1.0标准):
https://appcenter.intuit.com/api/v1/Connection/重新连接
我正在做的是:(它正在使用java)
Base64Encoder baseEncoder = Base64Encoder.getInstance();
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet("https://appcenter.intuit.com/api/v1/connection/reconnect");
StringBuilder headerReq = new StringBuilder();
headerReq.append("OAuth ");
headerReq.append("oauth_token=\"").append(OAUTHTOKEN).append("\"");
headerReq.append(", oauth_consumer_key=\"").append(CUNSUMER_KEY).append("\"");
headerReq.append(", oauth_signature_method=\"base64\"");
headerReq.append(", oauth_signature=\"") .append(baseEncoder.encode(PropsUtil.get(OAUTH_CONSUMER_SECRET).getBytes()))
.append(baseEncoder.encode("&".getBytes())) .append(baseEncoder.encode(symmetricEncrypter.decryptData(OAUTH_TOKEN_SECRET).getBytes())).append("\"");
headerReq.append(", oauth_version=\"1.0\"");
httpGet.addHeader("Authorization", headerReq.toString());
CloseableHttpResponse response = httpclient.execute(httpGet);
try {
System.out.println("Responsee::"+ response.getStatusLine());
}
而且,我得到的响应是:
<?xml version="1.0" encoding="utf-8"?>
<PlatformResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://platform.intuit.com/api/v1">
<ErrorMessage>This API requires Authorization.</ErrorMessage>
<ErrorCode>22</ErrorCode>
您能否建议我 为Oauth1.0 标准 创建请求时缺少的内容, 或者任何人都可以向我提供该标准上 Oauth1.0
请求示例的示例代码。
非常感谢你。
PFB工作代码。希望它会有用。
import java.io.InputStream;
import java.io.StringWriter;
import java.net.URI;
import java.net.URISyntaxException;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import oauth.signpost.signature.AuthorizationHeaderSigningStrategy;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.DefaultHttpClient;
import com.intuit.ipp.data.Account;
import com.intuit.ipp.exception.FMSException;
import com.intuit.ipp.net.MethodType;
import com.intuit.ipp.services.DataService;
public class POCWithoutDevkitTest {
private DataService service;
private OAuthConsumer oAuthConsumer;
private static String realmID = null;
public POCWithoutDevkitTest() {
realmID = "122294642099";
String consumerKey = "AAAAA";
String consumerSecret = "BBBBB";
String accessToken = "CCCCC";
String accessTokenSecret = "DDDDD";
setupContext(consumerKey, consumerSecret, accessToken, accessTokenSecret);
}
public void setupContext(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) {
this.oAuthConsumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
oAuthConsumer.setTokenWithSecret(accessToken, accessTokenSecret);
oAuthConsumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy());
}
public void authorize(HttpRequestBase httpRequest) throws FMSException {
try {
oAuthConsumer.sign(httpRequest);
} catch (OAuthMessageSignerException e) {
throw new FMSException(e);
} catch (OAuthExpectationFailedException e) {
throw new FMSException(e);
} catch (OAuthCommunicationException e) {
throw new FMSException(e);
}
}
public void executeGetRequest(String customURIString){
DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setParameter("http.protocol.content-charset", "UTF-8");
HttpRequestBase httpRequest = null;
URI uri = null;
try {
uri = new URI(customURIString);
} catch (URISyntaxException e) {
e.printStackTrace();
}
String methodtype = "GET";
if (methodtype.equals(MethodType.GET.toString())) {
httpRequest = new HttpGet(uri);
}
httpRequest.addHeader("content-type", "application/xml");
httpRequest.addHeader("Accept","application/xml");
try {
authorize(httpRequest);
} catch (FMSException e) {
e.printStackTrace();
}
HttpResponse httpResponse = null;
try {
HttpHost target = new HttpHost(uri.getHost(), -1, uri.getScheme());
httpResponse = client.execute(target, httpRequest);
System.out.println("Connection status : " + httpResponse.getStatusLine());
InputStream inputStraem = httpResponse.getEntity().getContent();
StringWriter writer = new StringWriter();
IOUtils.copy(inputStraem, writer, "UTF-8");
String output = writer.toString();
System.out.println(output);
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String args[]) {
POCWithoutDevkitTest withoutDevkitClient = new POCWithoutDevkitTest();
withoutDevkitClient.executeGetRequest("https://appcenter.intuit.com/api/v1/connection/reconnect");
}
}
依存关系
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-core</artifactId>
<version>1.2.1.1</version>
</dependency>
<dependency>
<groupId>oauth.signpost</groupId>
<artifactId>signpost-commonshttp4</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3.1</version>
</dependency>
谢谢
我已经在GitHub中上传了一个简单的REST API Java项目。如何在GitHub中通过调用API来查看API是否工作?我读过一些关于的文档,但不确定如何使用它。
问题内容: 我的任务是对elasticsearchAPI进行POST API调用, https://search-test-search-fqa4l6ubylznt7is4d5yxlmbxy.us- west-2.es.amazonaws.com/klove-ddb/recipe/_search 我以前没有对AWS服务进行API调用的经验。 所以,我尝试了- 但是我收到了{“ Message”:“
问题内容: 好的,这里是twitter API, 任何人都可以给我有关如何使用Meteor调用此API或链接的任何提示吗 更新:: 这是我尝试过的代码,但未显示任何响应 问题答案: 您要定义checkTwitter Meteor.method 内部 客户范围的块。因为您不能从客户端调用跨域(除非使用jsonp),所以您必须将此块放在一个块中。 顺便说一句,每个文档,在客户端的checkTwitte
问题内容: 我将Memcached用作django应用程序的后端。这段代码在普通的Django查询中可以正常工作: 但与django-rest-framework api调用一起使用时不起作用: 我将尝试提供缓存功能的DRF扩展: https://github.com/chibisov/drf-extensions 但github上的构建状态当前表示“构建失败”。 我的应用程序在api调用上非常繁
我使用postman测试了一个API。使用postman,我设法生成了一个令牌。 从postman那里,我通过一个get请求,使用以下内容和以下详细信息获取了用户的所有数据: 在授权类型下,我选择了“无记名令牌”并将令牌粘贴在其各自的字段中。 当我单击发送时,我得到了一个用户数据的成功响应。 在PHP中,如何在PHP函数中执行相同的api调用(使用id、电子邮件和令牌)? 我试过这个: 但当我查看
我有一个短信api在PHP,我打电话发送短信。我通过一些json和一个url回调来获得响应状态,短信被发送。 之后服务器调用我的回调url,但我不能得到响应体。$_GET和$_POST是空的...留档不存在。它应该有一些json。有人能帮帮我吗?提前感谢