在Android的工作不发布消息,LinkedIn与抄写员 [英] Post a message to LinkedIn with Scribe in not working in Android
问题描述
下面是code到发个帖子消息。在我的屏幕我有一个EditText部分,允许用户输入文本时,他们打中立柱SendMessage函数被调用。我一直在响应得到这个。我也曾尝试URLEn code.en code(有效载荷,UTF-8),以获得一间codeD字符串添加到身体和没有工作。任何有识之士将是有益的。
04-19 18:24:50.570:D /响应(693):其中,错误>
04-19 18:24:50.570:D /响应(693):其中,状态> 400℃/状态>
04-19 18:24:50.570:D /响应(693):其中,时间戳与GT; 1334859891007&下; /时间戳>
04-19 18:24:50.570:D /响应(693):<请求-ID> WJPI8VXQME&下; /请求-ID>
04-19 18:24:50.570:D /响应(693):其中,无差错code> 0℃; /无差错code>
04-19 18:24:50.570:D /响应(693):其中,消息>无法解析共享文件:错误:意外的文件结束后空< /消息>
04-19 18:24:50.570:D /响应(693):其中; /错误>
下面是code:
私有静态最后弦乐SendMessage函数=https://api.linkedin.com/v1/people/~/shares;公共无效的sendMessage(查看视图)
{
//获取作品就好了
// OAuthRequest REQ =新OAuthRequest(Verb.GEThttp://api.linkedin.com/v1/people/~/connections:(id,last-name));
//service.signRequest(accessToken,REQ);
//响应RES = req.send();
//Log.e(\"get,res.getBody()); OAuthRequest后=新OAuthRequest(Verb.POST,SendMessage函数); //也尝试添加< XML版本= \\1.0 \\编码= \\UTF-8 \\>有效载荷字符串的开头
字符串的有效载荷=<&份额GT; +
<注释和GT;测试与LT; /评论>中+
<能见度和GT;< code>任何与LT; / code>< /能见度和GT; +
< /股>中; post.addBodyParameter(身体,有效载荷);
post.addHeader(内容类型,文本/ XML的,字符集= UTF-8); service.signRequest(的accessToken,后);
尝试
{
响应响应= post.send();
Log.d(回应,response.getBody());
}
赶上(例外五)
{
e.printStackTrace();
}
LinkedInActivity.this.finish();
}
和我的服务被定义为:
=服务新ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey(API_KEY)
.apiSecret(API_SEC)
.callback(回调)
的.debug()
。建立();最后令牌requestToken = service.getRequestToken();
最后弦乐authURL = service.getAuthorizationUrl(requestToken);
我用网页视图捕捉回调保存验证/令牌。示例如下:
webView.setWebViewClient(新WebViewClient()
{
@覆盖
公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){ 如果(url.startsWith(OAuth的)){
webView.setVisibility(View.GONE); URI URI = Uri.parse(URL);
串验证= uri.getQueryParameter(oauth_verifier);
验证V =新的验证(验证); //保存令牌
的accessToken = service.getAccessToken(requestToken,V); 如果(uri.getHost()。等于(LinkedIn)){
editText.setText(appState.socialMediaMessage);
//将光标在predefined文本的末尾
editText.setSelection(editText.getText()长()); ;)editText.length( - textLimit = textLimit
textView.setText(将String.valueOf(textLimit)); } 返回true;
} 返回super.shouldOverrideUrlLoading(查看,网址);
}
}); //发送用户授权页面
webView.loadUrl(authURL);
使用:
post.addPayload(负载);
而不是:
post.addBodyParameter(体,有效载荷);
Below is the code to send a post message. On my screen i have an EditText section to allow the user to enter text and when they hit post the sendMessage function is called. I keep getting this in the response. I have also tried URLEncode.encode(payload, "UTF-8") to get an encoded string to add to the body and that did not work. Any insight would be helpful.
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>
Here is the code:
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();
}
and my service is being defined as:
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);
I use a webview to catch the callback to save the verifier/token. Example is below:
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);
use:
post.addPayload(payload);
instead of:
post.addBodyParameter("body", payload);
这篇关于在Android的工作不发布消息,LinkedIn与抄写员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!