2

我开发了一个应用程序,我正在使用 LinkedIn 集成来共享文本和图像,它在 HTC 手机中运行良好,但不适用于所有三星手机。请解决我的问题

我的java代码..

Button b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

        Intent i = new Intent(getApplicationContext(),LinkedInPost.class);
        startActivity(i);
    }
}

LinkedInPost.java

public class LinkedInPost extends Activity 
{
    // initializations

    public static final String CONSUMER_KEY = "key-key-key";
    public static final String CONSUMER_SECRET = "key-key-key";
    public static final String OAUTH_CALLBACK_SCHEME = "x-oauthflow-linkedin";
    public static final String OAUTH_CALLBACK_HOST = "techgene";
    public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + "://" + OAUTH_CALLBACK_HOST;


    final LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(CONSUMER_KEY,CONSUMER_SECRET);
    final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(CONSUMER_KEY, CONSUMER_SECRET);
    LinkedInRequestToken liToken;
    LinkedInApiClient client;

    private String strLinkedInMessage;
    private String strLinkTitle;
    private String strLink;

    //Called when the activity is starting.
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.linkedin);

        strLinkedInMessage  =   "04.17pm";
        strLinkTitle        =   "testing";
        strLink             =   "http://184.173.113.66/images/deal/rest_2012_3_18-0_1_27309-oysters-01.jpg";

        liToken = oAuthService.getOAuthRequestToken(OAUTH_CALLBACK_URL);

        try
        {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl()));
            startActivity(i);
        } 
        catch (Exception e) 
        {
            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_SHORT).show();
        }
    }

/** 
 * Method to verify the authentication, As it is used only in this package, it is made protected 
 */
@Override
protected void onNewIntent(Intent intent)
{
    try
    {
        String verifier = intent.getData().getQueryParameter("oauth_verifier");
        LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
        client = factory.createLinkedInApiClient(accessToken);
        client.postShare(strLinkedInMessage, strLinkTitle,strLink, strLink,VisibilityType.CONNECTIONS_ONLY);
        Toast.makeText(getBaseContext(), "In Try +ve", Toast.LENGTH_SHORT).show();
    }
    catch (Exception e) 
    {
        Toast.makeText(getBaseContext(), "onNewIntent", Toast.LENGTH_SHORT).show();
    }
    finish();
}

清单.xml

<activity
    android:name=".LinkedInPost"
    android:launchMode="singleInstance">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data
            android:host="techgene"
            android:scheme="x-oauthflow-linkedin" />
    </intent-filter>
</activity>

此代码在 htc 中工作正常,但在 logcat 中无法在三星中工作我这样的错误

10-02 06:16:07.312: E/AndroidRuntime(11708): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.LinkedInPost}: com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: api.linkedin.com
10-02 06:16:07.312: E/AndroidRuntime(11708): Caused by: com.google.code.linkedinapi.client.oauth.LinkedInOAuthServiceException: oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: api.linkedin.com
10-02 06:16:07.312: E/AndroidRuntime(11708):    at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
10-02 06:16:07.312: E/AndroidRuntime(11708):    at java.net.InetAddress.lookupHostByName(InetAddress.java:497)
10-02 06:16:07.312: E/AndroidRuntime(11708):    at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
4

2 回答 2

0

我希望你一定已经解决了这个问题,但我想我必须回复它:) 在我的案例中,我已经花了一周时间解决有线问题。请确保您的设备时间正确,因为linkedin服务器不会接受错误的时间并会报错。

于 2013-02-20T06:38:28.150 回答
0

您想api.linkedin.com在我的网络端调用 404 响应的页面。您应该检查是否为 OAuth 调用了正确的端点。

除了回答您的问题外,您不应在任何网站上发布您的 OAuth 凭据。

于 2012-08-29T13:43:54.020 回答