问题
I am converting an existing application from QBXML to use the QBOE API V3 for the QuickBooks Online accounts. I have managed to complete the OAuth and have what appears to be valid tokens/secrets using the DevDefined toolkit. I am stuck on generation of the oauth_signature. All the documentation points me to use the Intuit.Ipp DLL's however I can't because it is written to .net 4.0 framework and the server my application runs on only has 2.0 loaded. I can move my application but testing that upgrade would put me after the cut off deadline (4/16/2014). Is there a way I can build the signature using the DevDefined or some other option?
The application runs on IIS 6.0, DotNet Framework 2.0, with ASP.VB.
回答1:
Is the cutoff 4/16 now? I didn't see that announced anywhere. I thought it was 3/15.
I haven't tested this on .NET 2.0 but this just uses DevDefined without all the overhead. It will handle the signing and the http request for you.
using System.Text;
using DevDefined.OAuth.Consumer;
using DevDefined.OAuth.Framework;
// etc...
public void doGet()
{
IOAuthSession session = CreateSession();
string resp = session.Request().Get().ForUrl("https://quickbooks.api.intuit.com/v3/company/"
+ realmId + "/query?query=select * from customer where DisplayName='" + name + "'").ToString();
}
public void doPost(string Name)
{
IOAuthSession session = CreateSession();
string reqBody = "<Customer xmlns=\"http://schema.intuit.com/finance/v3\" domain=\"QBO\" sparse=\"false\">";
reqBody += "<DisplayName>" + Name + "</DisplayName>";
reqBody += "</Customer>";
byte[] bytes = Encoding.UTF8.GetBytes(reqBody);
session.ConsumerContext.UseHeaderForOAuthParameters = true;
IConsumerRequest req = session.Request().WithRawContentType("application/xml").WithRawContent(bytes);
req = req.WithAcceptHeader("application/xml");
req = req.ForUrl("https://quickbooks.api.intuit.com/v3/company/"
+ realmI + "/customer");
string resp = req.Post().ToString();
}
private IOAuthSession CreateSession()
{
OAuthConsumerContext consumerContext = new OAuthConsumerContext
{
ConsumerKey = Properties.Settings.Default.consumerKey,
ConsumerSecret = Properties.Settings.Default.consumerSecret,
SignatureMethod = SignatureMethod.HmacSha1
};
IOAuthSession session = new OAuthSession(consumerContext);
session.AccessToken = myAccessToken;
return session;
}
来源:https://stackoverflow.com/questions/22334796/build-a-signature-using-devdefined