我正在研究我的应用程序上的intuit集成。现在,我面临一个关于调用intuit的重新连接api的问题。我正在关注此引用:http://oauth.net/core/1.0a/
我正在尝试使用此代码::
Base64Encoder baseEncoder = Base64Encoder.getInstance();
Intuit intuit = IntuitLocalServiceUtil.getIntuit();// this is object, which stores the oauth Token and Oauth token secret.
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(intuit.getOauthToken()).append("\"");
headerReq.append(", oauth_consumer_key=\"").append(CommonConstants.INTUIT_QB_OAUTH_CONSUMER_KEY).append("\"");
headerReq.append(", oauth_signature_method=\"base64\"");
headerReq.append(", oauth_signature=\"")
.append(baseEncoder.encode(PropsUtil.get(CommonConstants.INTUIT_QB_OAUTH_CONSUMER_SECRET).getBytes()))
.append(baseEncoder.encode("&".getBytes()))
.append(baseEncoder.encode(symmetricEncrypter.decryptData(intuit.getOauthTokenSecret()).getBytes())).append("\"");
headerReq.append(", oauth_version=\"1.0\"");
httpGet.addHeader("Authorization", headerReq.toString());
System.out.println("Header Rwquesssssssssssst::::::" + 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>
<ServerTime>2014-08-16T18:15:45.6417185Z</ServerTime>
</PlatformResponse>
<?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>Authentication required</ErrorMessage>
<ErrorCode>22</ErrorCode>
<ServerTime>2014-08-16T18:15:47.3382208Z</ServerTime>
</PlatformResponse>
我使用邮递员测试了相同的东西,但我在响应时遇到了相同类型的错误。 我确信,我的密钥是有效的,他们现在正在工作。
(PS:我知道,那些密钥只能在150到180天内重新生成,但我期待intuit api的窗口绑定异常,但我没有得到那些类型的有效错误,我只是收到身份验证错误。)
谢谢。
答案 0 :(得分:2)
使用SignPost解决了这个问题,因为因纽特人的JAVA devkit有一个bug。
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>
谢谢。
答案 1 :(得分:1)
您使用的是哪种SDK? 对于PHP,您可以参考此示例 - https://gist.github.com/IntuitDeveloperRelations/8292870
对于dotnet-使用dev定义的调用 - 开发人员定义的调用示例 - https://gist.github.com/IntuitDeveloperRelations/0913b4c224de758fde0a
同样,您可以调用平台服务
Refer- https://developer.intuit.com/docs/0025_quickbooksapi/0053_auth_auth/oauth_management_api#Reconnect
请查看以下有关创建短期OAuth令牌以测试重新连接的说明。
在下面的链接中填写消费者密钥和消费者密钥。
产品:https://appcenter.intuit.com/Playground/OAuth/IA/?ck=&lt;&gt;&amp; cs =&lt;&gt;
或者,您可以在舞台或prod上导航到应用程序的“管理”页面,然后单击“测试连接到应用程序(OAuth)”。
在“访问令牌持续时间”字段中输入您希望发布的OAuth令牌的持续时间(例如,成功重新连接时为3600)。附加屏幕截图。
单击“连接到QuickBooks”按钮,浏览OAuth流程以授权与领域的连接。
在生成的“连接后交互”标题下,单击“重新连接API测试”。
将在您的OAuth令牌显示位置启动新页面。将这些值复制到您的应用程序以测试重新连接。