3

我正在PhoneGap 中开发一个应用程序,我想在Facebook、twitter 和LinkedIn 中共享文本消息。对于 ANDROID-LinkedIn,我正在搜索许多 Google 链接,但我得到了很好的链接。请帮助我,我在这里感到震惊

我正在实现这个示例:

<html>
    <head>
        <title>OAuthSimple w/ LinkedIn</title>
        <script src="OAuthSimple.js"></script>
        <script>
            /*
                You must edit the two following lines and put in your consumer key and shared secret
            */
            var consumer_key = "ibmay1qostgk";
            var shared_secret = "4HqeDRZ2ZKAvASlM";

            /*
                Nothing below here needs to be edited for the demo to operate
            */

            var oauth_info = {};
            var oauth = OAuthSimple(consumer_key, shared_secret);

            function parse_response(response, callback) 
            {
                response.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"), function($0, $1, $2, $3) { oauth_info[$1] = $3; });
                callback.call();
            }

            function authorize_url() 
            34{
                set_url("https://www.linkedin.com/uas/oauth/authenticate?oauth_token=" + oauth_info.oauth_token, document.getElementById("au"));
            }

            function access_token_url(pin) {
                oauth.reset();      
                var url = oauth.sign({action: "GET", path: "https://api.linkedin.com/uas/oauth/accessToken", parameters: {oauth_verifier: pin}, signatures: oauth_info}).signed_url;

                set_url(url, document.getElementById("at"));
            }

            function fetch_profile_url() {
                oauth.reset();  

                var url = oauth.sign({action: "GET", path: "https://api.linkedin.com/v1/people/~", signatures: oauth_info}).signed_url;

                set_url(url, document.getElementById("fp"));
            }

            function set_url(url, element) {
                element.value = url;

                var span = document.createElement("span");
                span.innerHTML = "&nbsp;&nbsp;<a href='" + url + "' target='_blank'>Open</a>";
                element.parentNode.insertBefore(span, element.nextSibling);
            }

            window.onload = function() {
                var url = oauth.sign({action: "GET", path: "https://api.linkedin.com/uas/oauth/requestToken", parameters: {oauth_callback: "oob"}}).signed_url;

                set_url(url, document.getElementById("rt"));
            }
        </script>
    </head>
    <body>
        <h1>OAuthSimple w/ LinkedIn</h1>
        <label for="rt">Request Token URL:</label> <input type="text" size="100" name="rt" id="rt" >
        <br><br>
        <label for="rtr">Request Token Response:</label><br><textarea rows="5" cols="75" name="rtr" id="rtr"></textarea>
        <br>
        <button onclick="javascript:parse_response(document.getElementById('rtr').value, authorize_url)">Parse Response</button>
        <br><br>
        <label for="au">Authorize URL:</label> <input type="text" size="100" name="au" id="au">
        <br><br>
        <label for="vp">Verifier PIN Code:</label> <input type="text" size="100" name="vp" id="vp">
        <button onclick="javascript:access_token_url(document.getElementById('vp').value)">Get Access Token URL</button>
        <br><br>
        <label for="at">Access Token URL:</label> <input type="text" size="100" name="at" id="at">
        <br><br>
        <label for="atr">Access Token Response:</label><br><textarea rows="5" cols="75" name="atr" id="atr"></textarea>
        <br>
        <button onclick="javascript:parse_response(document.getElementById('atr').value, fetch_profile_url)">Parse Response</button>
        <br><br>
        <label for="fp">Fetch Profile URL:</label> <input type="text" size="100" name="fp" id="fp">
    </body>
</html>

提前致谢

4

1 回答 1

3

这是使用 Phonegap 登录和发送 msg linkedIn 的完整示例

ref = window.open('https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=APIKEY&scope=w_messages r_network r_emailaddress r_fullprofile&state=APISECRET&redirect_uri=SOMEACTIVESITE','_blank','location=no');
    ref.addEventListener('loadstart', function(e){
        $.mobile.loading( 'show' );
        if(e.url.indexOf('?code=') >=0 ){
            if(e.url.match(/=[^]+&/)){
                var code = e.url.match(/=[^]+&/)[0].substring(1).replace('&','');
                window.sessionStorage.setItem('code', code);
                ref.close();

                $.ajax({
                    url: 'https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code='+code+'&redirect_uri=http://janbeeangeles.com&client_id=jwwwdjplwubu&client_secret=ygMy3EpVcs6IAORE',
                    success: function(a){

                        $.ajax({
                            url : 'https://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token='+a.access_token,
                            type: 'post',
                            headers : {
                                'Content-Type'  : 'application/json',
                                'x-li-format'   : 'json'
                            },
                            data: JSON.stringify({
                              "recipients": {
                                "values": [
                                {
                                  "person": {
                                    "_path": "/people/~",
                                   }
                                }]
                              },
                              "subject": "asdasdasd on your new position.",
                              "body": "You are certainly the best person for the job!"
                            }),
                            success: function(a){
                                alert(2222)
                            },
                            error: function(a){
                                alert(JSON.stringify(a))
                            }
                        })
                    },
                    error: function(a){
                        alert(JSON.stringify(a))
                    }
                })
            }
        }
    });
于 2013-04-17T11:04:25.293 回答