Android:Facebook Applink cURL 到 java
Android: Facebook Applink cURL to java
我一直在尝试将 cURL 命令翻译成 java 代码,以便我可以创建一个新的 AppLink 对象:https://developers.facebook.com/docs/applinks/hosting-api
我下载了 cURL,然后在 Windows 中输入了以下内容,它有效并返回了一个应用程序链接 ID:
curl -k -g https://graph.facebook.com/app/app_link_hosts -F
access_token="INSERTED MY OWN APP_TOKEN" -F name="Android App Link
Object Example" -F
android='[{"url":"sharesample://story/1234","package":"com.facebook.samples.sharesample","app_name":"ShareSample",},]'
-F web='{"should_fallback" : false,}'
有人知道如何将 curl 代码转换成 Java 以便我可以在我的服务器上使用它吗?
我还想知道是否有办法查询为特定包名称创建的所有应用程序链接,以便我可以看到创建的所有内容?
谢谢!
我花了几个小时研究这个,最后发现了这段 1997 年的代码,我认为它可能不再有效,因为方法已被弃用并针对 facebook 应用程序links 修改了它:http://www.javaworld.com/article/2077532/learn-java/java-tip-34--posting-via-java.html
然后我使用 Spring 生成了这个端点,现在它正在工作,returns 一个应用程序 link id:
@RequestMapping(value="/applink", method=RequestMethod.GET)
public void applink() {
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
try {
url = new URL ("https://graph.facebook.com/app/app_link_hosts");
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty
("Content-Type", "application/x-www-form-urlencoded");
// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream ());
String content =
"access_token=" + URLEncoder.encode("INSERT APP ACCESS TOKEN", "UTF-8") +
"&name=" + URLEncoder.encode("Android App Link Object Example", "UTF-8") +
"&android=" + URLEncoder.encode("[{'url':'sharesample://story/1234', 'package':'com.facebook.samples.sharesample','app_name':'ShareSample'}]", "UTF-8") +
"&web=" + URLEncoder.encode("{'should_fallback' : false}", "UTF-8");
printout.writeBytes(content);
printout.flush ();
printout.close ();
// Get response data.
input = new DataInputStream (urlConn.getInputStream ());
BufferedReader d = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String str;
while (null != ((str = d.readLine())))
{
System.out.println (str);
//textArea.appendText (str + "\n");
}
input.close ();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我一直在尝试将 cURL 命令翻译成 java 代码,以便我可以创建一个新的 AppLink 对象:https://developers.facebook.com/docs/applinks/hosting-api
我下载了 cURL,然后在 Windows 中输入了以下内容,它有效并返回了一个应用程序链接 ID:
curl -k -g https://graph.facebook.com/app/app_link_hosts -F access_token="INSERTED MY OWN APP_TOKEN" -F name="Android App Link Object Example" -F android='[{"url":"sharesample://story/1234","package":"com.facebook.samples.sharesample","app_name":"ShareSample",},]' -F web='{"should_fallback" : false,}'
有人知道如何将 curl 代码转换成 Java 以便我可以在我的服务器上使用它吗?
我还想知道是否有办法查询为特定包名称创建的所有应用程序链接,以便我可以看到创建的所有内容?
谢谢!
我花了几个小时研究这个,最后发现了这段 1997 年的代码,我认为它可能不再有效,因为方法已被弃用并针对 facebook 应用程序links 修改了它:http://www.javaworld.com/article/2077532/learn-java/java-tip-34--posting-via-java.html
然后我使用 Spring 生成了这个端点,现在它正在工作,returns 一个应用程序 link id:
@RequestMapping(value="/applink", method=RequestMethod.GET)
public void applink() {
URL url;
URLConnection urlConn;
DataOutputStream printout;
DataInputStream input;
try {
url = new URL ("https://graph.facebook.com/app/app_link_hosts");
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty
("Content-Type", "application/x-www-form-urlencoded");
// Send POST output.
printout = new DataOutputStream (urlConn.getOutputStream ());
String content =
"access_token=" + URLEncoder.encode("INSERT APP ACCESS TOKEN", "UTF-8") +
"&name=" + URLEncoder.encode("Android App Link Object Example", "UTF-8") +
"&android=" + URLEncoder.encode("[{'url':'sharesample://story/1234', 'package':'com.facebook.samples.sharesample','app_name':'ShareSample'}]", "UTF-8") +
"&web=" + URLEncoder.encode("{'should_fallback' : false}", "UTF-8");
printout.writeBytes(content);
printout.flush ();
printout.close ();
// Get response data.
input = new DataInputStream (urlConn.getInputStream ());
BufferedReader d = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String str;
while (null != ((str = d.readLine())))
{
System.out.println (str);
//textArea.appendText (str + "\n");
}
input.close ();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}