簡體   English   中英

使用Scribe無法向Android發送信息到LinkedIn

[英]Post a message to LinkedIn with Scribe in not working in Android

以下是發送帖子消息的代碼。 在我的屏幕上,我有一個EditText部分,以允許用戶輸入文本,然后在他們單擊后調用sendMessage函數。 我一直在回應中得到這個。 我還嘗試了URLEncode.encode(payload,“ UTF-8”)來獲取要添加到正文中的編碼字符串,但是這樣做不起作用。 任何見解都會有所幫助。

04-19 18:24:50.570: D/response(693): <error>
04-19 18:24:50.570: D/response(693):   <status>400</status>
04-19 18:24:50.570: D/response(693):   <timestamp>1334859891007</timestamp>
04-19 18:24:50.570: D/response(693):   <request-id>WJPI8VXQME</request-id>
04-19 18:24:50.570: D/response(693):   <error-code>0</error-code>
04-19 18:24:50.570: D/response(693):   <message>Couldn't parse share document: error: Unexpected end of file after null</message>
04-19 18:24:50.570: D/response(693): </error>

這是代碼:

private static final String SendMessage = "https://api.linkedin.com/v1/people/~/shares";

public void sendMessage(View view)
{
    //Get works just fine
    //OAuthRequest req = new OAuthRequest(Verb.GET, "http://api.linkedin.com/v1/people/~/connections:(id,last-name)");
    //service.signRequest(accessToken, req);
    //Response res = req.send();
    //Log.e("get", res.getBody());

    OAuthRequest post = new OAuthRequest(Verb.POST, SendMessage);

    //Have also  tried adding <?xml version=\"1.0\" encoding=\"UTF-8\"?>" to the beginning of the payload string        
    String payload = "<share>" +
                        "<comment>testing</comment>" +
                        "<visibility><code>anyone</code></visibility>" +
                     "</share>";

    post.addBodyParameter("body", payload);
    post.addHeader("Content-Type", "text/xml;charset=UTF-8");

    service.signRequest(accessToken, post);
    try
    {
        Response response = post.send();
        Log.d("response",response.getBody());
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    LinkedInActivity.this.finish();
}

並且我的服務被定義為:

service = new ServiceBuilder()
                .provider(LinkedInApi.class)
                .apiKey(API_KEY)
                .apiSecret(API_SEC)
                .callback(CALLBACK)
                .debug()
                .build();

final Token requestToken = service.getRequestToken();
final String authURL = service.getAuthorizationUrl(requestToken);

我使用webview捕獲回調以保存驗證者/令牌。 示例如下:

webView.setWebViewClient(new WebViewClient()
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if(url.startsWith("oauth")){
                webView.setVisibility(View.GONE);

                Uri uri = Uri.parse(url);
                String verifier = uri.getQueryParameter("oauth_verifier");
                Verifier v = new Verifier(verifier);

                //save token
                accessToken = service.getAccessToken(requestToken, v);

                if(uri.getHost().equals("linkedIn")){
                    editText.setText(appState.socialMediaMessage);
                    //place the cursor at the end of the predefined text
                    editText.setSelection(editText.getText().length());

                    textLimit = textLimit - editText.length();
                    textView.setText(String.valueOf(textLimit));

                }

                return true;
            }

            return super.shouldOverrideUrlLoading(view, url);
        }
    });

    //send user to authorization page
    webView.loadUrl(authURL);

采用:

post.addPayload(payload);

代替:

post.addBodyParameter("body", payload);

暫無
暫無

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

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