【发布时间】:2021-06-16 04:46:52
【问题描述】:
我正在尝试制作一个函数应用,它从逻辑应用获取 JSON 数据,然后将其发送到 Eloqua API。
我一直在用the Eloqua documentation in order to set it up.
但是,我遇到了问题。
我似乎没有从我的逻辑应用程序中获取任何数据,或者无法解析从您发送的第一个 OAuth2 网址获得的网址。
我想知道是否有人知道我犯了什么错误,因为我在这方面有点初级,并不完全确定我做错了什么。
这是我用于我的函数应用程序的代码: 主要功能
/*
* Sets up the needed variables for sending to Eloqua
*/
string clientSecreat = "xxxxx";
var authentication = System.Text.Encoding.UTF8.GetBytes(clientSecreat);
string getJson = req.GetQueryNameValuePairs()
.FirstOrDefault(q => string.Compare(q.Key, "Body", true) == 0)
.Value;
/*
* Starts by calling to get token for Oauth2
*/
var client = new RestClient("https://login.eloqua.com/auth/oauth2/authorize?");
var request = new RestRequest(Method.GET);
var queryResult = client.Execute<Token>(request);
//log.Info(queryResult.ToString());
client = new RestClient("https://login.eloqua.com/auth/oauth2/token");
request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Authorization", "Basic " + authentication);
request.AddJsonBody("grant_type: ", "authorization_code");
request.AddJsonBody("code: " + queryResult);
request.AddJsonBody("redirect_uri: ", "redirect_url");
var response = await client.ExecuteAsync<AccessToken>(request);
log.Info(response.ToString());
/*
* Posts the Logic App parsed JSON data
*/
client = new RestClient("https://secure.p06.eloqua.com/API/Bulk/2.0/customObjects/377/imports/1904470/data");
request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;
request.AddHeader("Content_Type: ", "application/json");
request.AddHeader("Authorization: ", "Basic " + response);
request.AddJsonBody(getJson);
var execute = await client.ExecuteAsync(request);
return req.CreateResponse("Success");
Token.cs:
public class Token
{
[JsonProperty("code")]
public string code { get; set; }
}
AccessToken.cs:
public class AccessToken
{
[JsonProperty("access_token")]
public string access_token { get; set; }
}
提前谢谢你。
【问题讨论】:
-
根据代码,使用授权码流程获取token,然后调用API。我们不能在 Azure 函数中这样做。因为如果我们使用这种方式,我们需要打开一个页面来输入用户名和密码。但是Azure函数无法打开页面..所以我建议你使用
resource owner password credentials grant流来获取令牌并调用API -
如何实现才能使用
resource owner password credentials grant?对不起,如果这是一个愚蠢的问题。
标签: c# azure-logic-apps restsharp azure-function-app eloqua