【问题标题】:Android Facebook-SDK multipart/form-data upload got "Invalid OAuth access token"Android Facebook-SDK 多部分/表单数据上传得到“无效的 OAuth 访问令牌”
【发布时间】:2011-03-23 02:26:51
【问题描述】:

我使用 HttpCilent 4.0.1 上传图片,但我得到 HTTP 400 错误,这样的错误信息,请有人帮助我。

{"error":{"type":"OAuthException","message":"无效 OAuth 访问令牌。"}}

我的代码是...

private void uploadPicture( ) throws ParseException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams( ).setParameter( CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1 );

    HttpPost httppost = new HttpPost( "https://graph.facebook.com/me/photos" );
    File file = new File( sdpicturePath );

    // DEBUG
    Log.d( "TSET", "FILE::" + file.exists( ) ); // IT IS NOT NULL
    Log.d( "TEST", "AT:" + fbAccessToken ); // I GOT SOME ACCESS TOKEN

    MultipartEntity mpEntity  = new MultipartEntity( );
    ContentBody cbFile        = new FileBody( file, "image/png" );
    ContentBody cbMessage     = new StringBody( "TEST TSET" );
    ContentBody cbAccessToken = new StringBody( fbAccessToken );

    mpEntity.addPart( "access_token", cbAccessToken );
    mpEntity.addPart( "source",       cbFile        );
    mpEntity.addPart( "message",      cbMessage     );        

    httppost.setEntity( mpEntity );

    // DEBUG
    System.out.println( "executing request " + httppost.getRequestLine( ) );
    HttpResponse response = httpclient.execute( httppost );
    HttpEntity resEntity = response.getEntity( );

    // DEBUG
    System.out.println( response.getStatusLine( ) );
    if (resEntity != null) {
      System.out.println( EntityUtils.toString( resEntity ) );
    } // end if

    if (resEntity != null) {
      resEntity.consumeContent( );
    } // end if

    httpclient.getConnectionManager( ).shutdown( );
} // end of uploadPicture( )

【问题讨论】:

    标签: android upload multipart facebook


    【解决方案1】:

    您收到的访问令牌需要进行 URL 解码。我使用 URLDecoder.decode() 和 MultiPartEntity(HttpMultipartMode.STRICT);

    【讨论】:

      猜你喜欢
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      • 2016-11-15
      • 2019-04-28
      • 2013-02-27
      • 1970-01-01
      相关资源
      最近更新 更多