簡體   English   中英

使用Android上的SoundCloud API發布到Twitter和Facebook

[英]Posting to Twitter and Facebook using the SoundCloud API on Android

上傳音頻文件時,使用SoundCloud API將其發布到Twitter和Facebook時遇到一些麻煩。 我已經從SoundCloud網站配置了Twitter和Facebook的預先存在的連接設置。 我已經通過在“ / me / connections”上使用GET請求來驗證它們都處於活動狀態。

我不確定要用於發布到社交網絡的參數。 我已經嘗試過“ post_to”,“ shared_to”,“ shared-to”和“ share_to”。 http://developers.soundcloud.com/docs/api/guide#uploading上的API表示使用“ shared_to”,但未包含在com.soundcloud.api.Params ,當我收到HTTP 422未知錯誤時,手動輸入字符串。 位於http://developers.soundcloud.com/blog/ios-sharing的iOS共享指南使用“ post_to”,並且包含在com.soundcloud.api.Params但是當我使用它時,它會將音頻文件發布到SoundCloud,但不會t將任何消息發布到Twitter和Facebook。 這是我正在使用的代碼:

HttpResponse httpResp = Api.wrapper.get(Request.to(Endpoints.MY_CONNECTIONS));

JSONArray jsonCons = new JSONArray(Http.getString(httpResp));
String[] cons = new String[jsonCons.length()];
JSONObject jsonTemp;
for(int i = 0; i < jsonCons.length(); i++) {
    jsonTemp = jsonCons.getJSONObject(i);
    cons[i] = Integer.toString(jsonTemp.getInt("id"));;
}

httpResp = Api.wrapper.post(Request.to(Endpoints.TRACKS)
    .withFile(Params.Track.ASSET_DATA, file)
    .add(Params.Track.TITLE, file.getName())
    .add(Params.Track.SHARING, Params.Track.PUBLIC)
    .add(Params.Track.POST_TO, cons)
//  .add("track[shared_to][][id]", cons)
    .setProgressListener(new Request.TransferProgressListener() {
        @Override
        public void transferred(long l) throws IOException {
            if (isCancelled()) throw new IOException("canceled");
            publishProgress(l, file.length());
        }
    }));

在SoundCloud配置文件中,我還可以將其設置為在新上傳的聲音上自動發布,並且只要不包含“ post_to”的參數即可將其發布到Twitter和Facebook,但我希望能夠控制什么內容和時間我發。 我將不勝感激,您可以提供任何幫助。

謝謝

澄清:

  • shared_to用於共享特定的用戶ID /電子郵件
  • post_to適用於社交網絡

不幸的是,包裝器上的add(String, Object)方法不接受數組/集合,因此您必須像這樣添加它們:

httpResp = Api.wrapper.post(Request.to(Endpoints.TRACKS)
  .add("track[shared_to][emails][][address]", "foo@example.com")
  .add("track[shared_to][emails][][address]", "baz@example.com")
  .add("track[shared_to][users][][id]",       "1")
  .add("track[shared_to][users][][id]",       "2")
  .add("track[post_to][][id]",                "3")
  .add("track[post_to][][id]",                "4")

我已經修復了包裝器( 1 ),下一個發行版將在“ add”調用中支持集合/數組,與此同時,您可以使用快照版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM