Ikwu Isi ọdịnaya

Mepụta akwụkwọ ozi

Mgbe ha gụsịrị ya chọrọ nhazi, ị nwere ike ịmepụta ihe atụ si window.Predis. Ihe atụ a na-enye ohere ịnweta ụzọ SDK niile. Nke createPost ọrụ malite na Predis iFrame interface, na-enyere ndị ọrụ aka ịmepụta na dezie posts n'enweghị nsogbu.

const predis = new window.Predis();

// Event callbacks should be registered before initialization to capture any initialization errors
predis.on("ready", () => {
predis.createPost({
onPostPublish: function (err, data) {
if (err) {
console.error("Error publishing post:", err);
} else {
console.log("Post published successfully:", data);
}
},
});
});

predis.on("error", (error) => {
console.error("SDK Error:", error);
});

predis.initialize({ appId: "YOUR_APP_ID" });
mkpa

Ndị na-ahụ maka ihe omume debanye aha site na iji .on() tupu ịkpọ oku initialize(). The createPost a ghaghị iji usoro a mee ihe naanị n'ime ready oku azụ iji hụ na ebidola SDK ahụ nke ọma.

The createPost Usoro bụ isi interface maka ịmalite ịmepụta post na idezi usoro ọrụ.

Ihe Nlereanya Mmezu zuru okeNa

Ihe atụ na-esonụ na-egosi mmejuputa iwu zuru oke nke Predis SDK maka imepụta akwụkwọ ozi:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Predis SDK Integration</title>
</head>

<!-- Predis.ai SDK -->
<script
type="text/javascript"
src="https://predis.ai/sdk/embed.js"
async
defer
crossorigin="anonymous"
></script>

<body>
<!-- Button to launch the post creator/editor -->
<button id="generate-post-button">Generate Post</button>

<script type="text/javascript">
document.getElementById("generate-post-button").addEventListener("click", function () {
try {
// Create an instance of the Predis SDK
const predis = new window.Predis();

// Handle successful initialization
predis.on("ready", () => {
console.log("SDK initialized successfully");

predis.createPost({
onPostPublish: function (err, data) {
if (err) {
console.error("Error during post publication:", err);
// Handle error appropriately in your application
} else {
console.log("Post published successfully:", data);
// Process the published post data
}
},
});
});

// Handle SDK errors
predis.on("error", (error) => {
console.error("SDK Error:", error);
// Implement error handling logic
});

// Initialize the SDK with your application ID
predis.initialize({ appId: "YOUR_APP_ID" });

} catch (error) {
console.error("Failed to initialize Predis SDK:", error);
}
});
</script>
</body>
</html>