gpt4 book ai didi

javascript - 将 adobe creative SDK 集成到 Web 应用程序时,我得到 : {"error" :"invalid_credentials"}

转载 作者:行者123 更新时间:2023-11-30 08:27:56 34 4
gpt4 key购买 nike

我已经关注了 Web: Getting Started Samples .当调用函数 AdobeCreativeSDK.init 时,它会调用 https://adobeid-na1.services.adobe.com/ims/check/v4/token首先使用请求方法 OPTIONS,然后使用请求方法 POST,两者都返回状态代码 200 OK。对 POST 请求的响应返回 {"error":"invalid_credentials"} 我不知道为什么以及如何解决这个问题。

我们将不胜感激。

最佳答案

故障排除:

你在你的控制台中看到这样的东西吗?

XMLHttpRequest cannot load https://adobeid-na1.services.adobe.com/ims/check/v4/token. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://your.domain.com' is therefore not allowed access.

那么您可能没有有效的 SSL 证书。


来自文档:

来自 Adob​​e 的 Getting started with the Creative SDK for Web :

If you get an XMLHttpRequest error due to 'Access-Control-Allow-Origin', there is likely an issue with your SSL setup (as noted in the “Prerequisites” section of this guide, SSL is required).

这是先决条件部分中所述的[强调]:

Prerequisites

  1. Before you can work with the Creative SDK, you must register your application and get Client ID (API Key) and Client Secret values. For details, see the “Registering Your Application” section of this guide.

  2. The following software is required:

    • Supported browsers: Chrome 53+, Safari 9+, Firefox 45+, Edge, IE11+
    • SSL required: Your site must support SSL on any page that integrates the Creative SDK.

可能的解决方案:

如果您从 localhost 在您的开发机器上进行测试,那么您需要修改您的 hosts 文件并设置您自己的域映射到 127.0.0.1,那么您需要在您的服务器上配置一个自签名证书。

您可能还想查看 How to use locally (来自他们的 Github 存储库)有这个美妙的 gem :

openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes

有用的资源:


我是如何让它工作的:

1。 Adobe I/O 设置:

以下是我的测试应用程序在 Adob​​e I/O 上的配置方式:

enter image description here

2。本地 HTTP 服务器 (SSL)

在根目录下,创建一个自签名证书,运行:

openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes

然后,我设置了一个简单的 python 服务器,它使用上面创建的自签名证书 server.pem:

# ./start.py
import BaseHTTPServer, SimpleHTTPServer
import ssl

httpd = BaseHTTPServer.HTTPServer(('localhost', 4443), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='server.pem', server_side=True)
httpd.serve_forever()

启动我的服务器

python ./start.py

3。打 https://localhost:4443

重要提示:您将在第二次调用中收到带有以下负载的 200 响应:{"error":"invalid_credentials"}。只要您没有收到控制台错误,您的 Web 应用程序就准备好了。

根据文档,我添加了一个带有 csdk-login 的按钮来测试 User Auth UI api。


4。完整的工作代码

文件结构:

/app
├── config.js <-- my clientId config
├── index.html
├── index.js
├── server.pem <-- my self-signed cert
└── start.py <-- my server

HTML:

<!DOCTYPE html>
<html>
<head>
<title>Technophobia: SDK Getting Started</title>
</head>
<body>
<h1>Adobe Creative SDK</h1>
<p>Look at the console</p>

<button id="csdk-login">Log in to Creative Cloud</button>

<script type="text/javascript" src="https://cdn-creativesdk.adobe.io/v1/csdk.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="index.js"></script>

</body>
</html>

JS:

/* 1) Initialize the AdobeCreativeSDK object */
AdobeCreativeSDK.init({
/* 2) Add your Client ID (API Key) */
clientID: CONFIG.CSDK_CLIENT_ID, //
API: ["Asset"],
onError: function(error) {
/* 3) Handle any global or config errors */
if (error.type === AdobeCreativeSDK.ErrorTypes.AUTHENTICATION) {
console.log('You must be logged in to use the Creative SDK');
} else if (error.type === AdobeCreativeSDK.ErrorTypes.GLOBAL_CONFIGURATION) {
console.log('Please check your configuration');
} else if (error.type === AdobeCreativeSDK.ErrorTypes.SERVER_ERROR) {
console.log('Oops, something went wrong');
}
}
});

/* 1) Add a click handler to a button that calls a helper function */
document.getElementById("csdk-login").addEventListener('click', handleCsdkLogin, false);

/* 2) Make a helper function */
function handleCsdkLogin() {

/* 3) Get auth status */
AdobeCreativeSDK.getAuthStatus(function(csdkAuth) {

/* 4) Handle auth based on status */
if (csdkAuth.isAuthorized) {
// The user is logged in and has authorized your site.
console.log('Logged in!');
} else {
// Trigger a login
AdobeCreativeSDK.login(handleCsdkLogin);
}
});
}

关于javascript - 将 adobe creative SDK 集成到 Web 应用程序时,我得到 : {"error" :"invalid_credentials"},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42230546/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com