gpt4 book ai didi

java - 使用 Scribe 在 Android 中无法工作的情况下向 LinkedIn 发送消息

转载 作者:行者123 更新时间:2023-12-02 00:24:46 27 4
gpt4 key购买 nike

下面是发送帖子消息的代码。在我的屏幕上,我有一个 EditText 部分,允许用户输入文本,当他们点击 post 时,将调用 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 来捕获回调以保存 validator/ token 。示例如下:

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);

关于java - 使用 Scribe 在 Android 中无法工作的情况下向 LinkedIn 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10246770/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com