using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
static async Task Main(string[] args)
{
string host = "https://open.explinks.com";
string path = "/v2/scd2024041701861d19d840/generate-animated-gif";
string appCode = "{{AppCode}}"; // 替換為您的AppCode

using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("X-Mce-Signature", $"AppCode/{appCode}");
client.DefaultRequestHeaders.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

var content = new Dictionary<string, string>
{
{ "img", "img_base64_string_here" } // 替換為實際數(shù)據(jù)
};

var response = await client.PostAsync(host + path, new FormUrlEncodedContent(content));
string responseContent = await response.Content.ReadAsStringAsync();

Console.WriteLine("HTTP 狀態(tài)碼: " + (int)response.StatusCode);
Console.WriteLine("響應內(nèi)容: " + responseContent);
}
}
}

C++集成API案例

以下是使用C++調(diào)用動圖生成API 的示例代碼:

#include <iostream>
#include <curl/curl.h>

static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}

int main()
{
CURL* curl;
CURLcode res;
std::string readBuffer;

curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();

if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://open.explinks.com/v2/scd2024041701861d19d840/generate-animated-gif");
curl_easy_setopt(curl, CURLOPT_POST, 1L);

struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "X-Mce-Signature: AppCode/{{AppCode}}"); // 替換為您的AppCode
headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

std::string postFields = "img=img_base64_string_here"; // 替換為實際數(shù)據(jù)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postFields.c_str());

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);

res = curl_easy_perform(curl);

if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
else
std::cout << "響應內(nèi)容: " << readBuffer << std::endl;

curl_easy_cleanup(curl);
}

curl_global_cleanup();
return 0;
}

Ruby集成API案例

以下是使用Ruby調(diào)用動圖生成API 的示例代碼:

require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://open.explinks.com/v2/scd2024041701861d19d840/generate-animated-gif")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/x-www-form-urlencoded"
request["X-Mce-Signature"] = "AppCode/{{AppCode}}" # 替換為您的AppCode
request.set_form_data(
"img" => "img_base64_string_here" # 替換為實際數(shù)據(jù)
)

req_options = {
use_ssl: uri.scheme == "https"
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end

puts "HTTP 狀態(tài)碼: #{response.code}"
puts "響應內(nèi)容: #{response.body}"

這些示例代碼展示了如何在不同編程語言中調(diào)用動圖生成API,可以根據(jù)實際需要進行修改和擴展。

動圖生成API是否有替換方案?

如果你在尋找動圖生成API的替代方案,有許多其他工具和服務可以滿足不同的需求。以下是一些常見的替代方案,包括各自的特點和適用場景:

1. Giphy API

優(yōu)點:

缺點:

2. Tenor API

優(yōu)點:

缺點:

如何找到動圖生成API

冪簡集成是國內(nèi)領先的API集成管理平臺,專注于為開發(fā)者提供全面、高效、易用的API集成解決方案。冪簡API平臺可以通過以下兩種方式找到所需API:通過關鍵詞搜索API(例如,輸入’人臉識別‘這類品類詞,更容易找到結果)、或者從API Hub分類頁進入尋找。

此外,冪簡集成博客會編寫API入門指南、多語言API對接指南、API測評等維度的文章,讓開發(fā)者快速使用目標API。

上一篇:

構建未來區(qū)塊鏈應用:一站式Blockchain集成API實踐指南

下一篇:

AI內(nèi)容太死板?試試人性化智能AI寫作AISEO API!
#你可能也喜歡這些API文章!

我們有何不同?

API服務商零注冊

多API并行試用

數(shù)據(jù)驅動選型,提升決策效率

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

對比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉化潛力

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費