0

我创建了从 upwork.com 获取信息的应用程序。我使用 java lib 和 Upwork OAuth 1.0。问题是对 API 的本地请求工作正常,但是当我部署到 Google Cloud 时,我的代码不起作用。我得到 ({"error":{"code":"503","message":"Exception: IOException"}})。

我创建 UpworkAuthClient 以返回 OAuthClient,然后将其用于 JobClient 中的请求。

run() {
   UpworkAuthClient upworkClient = new UpworkAuthClient();
   upworkClient.setTokenWithSecret("USER TOKEN", "USER SECRET");
   OAuthClient client = upworkClient.getOAuthClient();

   //set query
   JobQuery jobQuery = new JobQuery();
   jobQuery.setQuery("query");
   List<JobQuery> jobQueries = new ArrayList<>();
   jobQueries.add(jobQuery);

   // Get request of job
   JobClient jobClient = new JobClient(client, jobQuery);
   List<Job> result = jobClient.getJob();
}

public class UpworkAuthClient {
    public static final String CONSUMERKEY = "UPWORK KEY";
    public static final String CONSUMERSECRET = "UPWORK SECRET";
    public static final String OAYTРCALLBACK = "https://my-app.com/main";

    OAuthClient client ;

    public UpworkAuthClient() {
        Properties keys = new Properties();
        keys.setProperty("consumerKey", CONSUMERKEY);
        keys.setProperty("consumerSecret", CONSUMERSECRET);
        Config config = new Config(keys);
        client = new OAuthClient(config);
    }

    public void setTokenWithSecret (String token, String secret){
        client.setTokenWithSecret(token, secret);
    }

    public OAuthClient getOAuthClient() {
        return client;
    }

    public String getAuthorizationUrl() {
        return this.client.getAuthorizationUrl(OAYTРCALLBACK);
    }
}

public class JobClient {
    private JobQuery jobQuery;
    private Search jobs;

    public JobClient(OAuthClient oAuthClient, JobQuery jobQuery) {
        jobs = new Search(oAuthClient);
        this.jobQuery = jobQuery;
    }

    public List<Job> getJob() throws JSONException {
        JSONObject job = jobs.find(jobQuery.getQueryParam());
        jobList = parseResponse(job);
        return jobList;
    }
}

本地开发服务器工作正常,我在本地机器上得到了 resilts,但在云中没有。我会很高兴有任何想法,谢谢!

4

1 回答 1

0
{"error":{"code":"503","message":"Exception: IOException"}}

看起来不像是 Upwork API 的响应返回。您能否提供完整的响应,包括返回的标头?因此,我们将对其进行更精确的研究。

于 2019-02-26T16:00:10.713 回答