我正在开发一个项目,以自动将用户添加/删除到 ITunesConnect - TestFlight,用于我在 appstore 中的一个应用程序。
我使用以下命令成功地使用 fastlane 试点工具 ( https://docs.fastlane.tools/actions/pilot/ ) 为我的应用添加/删除了测试人员。
bundle exec fastlane pilot add hareesh@test.com -a com.abc.MyApp
bundle exec fastlane pilot remove hareesh@test.com -a com.abc.MyApp
我想使用后端是 Java 的 UI 来做同样的事情。我在下面的链接中找到了 REST 端点
https://github.com/fastlane/itc-api-docs/ https://github.com/fastlane/itc-api-docs#register-new-external-beta-tester
但是我写的代码不能正常工作,无法将测试仪添加到TestFlight中。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.auth.AuthenticationException;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
public class TestFlightCreateTester {
public static void main(String[] args) throws AuthenticationException, ClientProtocolException, IOException {
RequestConfig customizedRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).build();
HttpClientBuilder customizedClientBuilder = HttpClients.custom().setDefaultRequestConfig(customizedRequestConfig);
CloseableHttpClient client = customizedClientBuilder.build();
HttpPost httpPost = new HttpPost("https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/users/pre/create");
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("testUserName", "testPassword");
httpPost.addHeader(new BasicScheme().authenticate((Credentials) creds, httpPost,null));
String json = "{\"testers\":[{\"emailAddress\":{\"value\":\"hareesh@test.com\",\"errorKeys\":[]},\"firstName\":{\"value\":\"Hareesh\"},\"lastName\":{\"value\":\"Sarma\"},\"testing\":{\"value\":true},\"groups\":[]}]}";
StringEntity entity = new StringEntity(json);
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
CloseableHttpResponse response = client.execute(httpPost);
BufferedReader r = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuilder total = new StringBuilder();
String line = null;
while ((line = r.readLine()) != null) {
total.append(line);
}
System.out.println(total.toString());
response.close();
}
}
当我运行上述代码时,我得到以下响应
UnauthenticatedRequest ID: XXXXXXXXXXXXXXXX.0.0