【问题标题】:share data to LinkedIn api User’s Profile for status update将数据共享到 LinkedIn api 用户的个人资料以更新状态
【发布时间】:2012-06-18 09:58:50
【问题描述】:

我正在开发一个与 LinkedIn 用户个人资料共享数据的程序。我正在使用 Delphi XE2、OAuth 和 LinkedIn API。我能够获得访问令牌。然后我想更新状态。所以我的代码是

procedure TForm1.Button2Click(Sender: TObject);
var
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL ;
Url,sign  : String;
Response     : TStringStream;
slist        : TStringList;
str          : WideString;
Arequest1    : TOAuthRequest;
AuthHeader   : WideString;
begin
   with http do
   Begin
    IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlerSOcketOpenSSL.Create(nil);
    with idSSLIOHandlerSocketOpenSSL1 do
    begin
      SSLOptions.Method := sslvTLSv1;
      SSLOptions.SSLVersions := [sslvTLSv1];
      SSLOptions.Mode := sslmBoth;
      SSLOptions.VerifyMode := [];
      SSLOptions.VerifyDepth := 0;
      host := '';
    end;
    IOHandler := IdSSLIOHandlerSocketOpenSSL1;
    AllowCookies := True;
    Request.ContentRangeEnd := 0;
    Request.ContentRangeStart := 0;
    Request.ContentType := 'application/xml';
    Request.ContentEncoding := 'utf-8';
    Request.BasicAuthentication := False;
    Request.Connection   := 'Keep-Alive';
    request.host := 'api.linkedin.com';
    Request.Accept := 'text/xml, */*';
    Request.UserAgent  :=  'Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0' ;
    HTTPOptions := [hoForceEncodeParams];
   end;
     Url := 'https://api.linkedin.com/v1/people/~/shares';
     Consumer    := nil;
     Consumer    := TOAuthConsumer.Create(ConsumerKey, ConsumerSecret);
     Arequest1   := TOAuthRequest.Create(Url);
     sign        := HMAC.build_signature(Arequest1,Consumer,Token);
     sign        := TOAuthUtil.urlEncodeRFC3986(sign);
     http.Request.CustomHeaders.Clear;
     AuthHeader     := 'OAuth '+ 'oauth_nonce="'+Arequest1.GenerateNonce+'",'+  'oauth_signature_method="'+HMAC.get_name+'",'+ 'oauth_timestamp="'+Timestamp+'",'+ 'oauth_consumer_key="'+Consumer.Key+'",'+ 'oauth_token="'+Token.Key+'",'+ 'oauth_signature="'+sign+'",'+ 'oauth_version="1.0"';
      http.Request.CustomHeaders.Add(AuthHeader);
      slist       := TStringList.Create;

      slist.Text  := '<?xml version="1.0" encoding="UTF-8"?><share><comment>Posting from the API using XML</comment>'+
                     '<content><title>A title for your share</title><submitted-url>http://developer.linkedin.com</submitted-url>'+
                     '<submitted-image-url>http://lnkd.in/Vjc5ec</submitted-image-url></content><visibility>'+
                     '<code>anyone</code></visibility></share>';
    Response    := TStringStream.Create;
    http.Request.ContentLength  := length(slist.Text);
  try
     http.post(Url,slist,Response);
  Finally
    ShowMessage(Response.DataString);
    http.Free;
    ARequest.Free;
  end;
end;

我正面临 401 未授权。请检查我的问题@A1rPun。请帮帮我

【问题讨论】:

    标签: delphi linkedin


    【解决方案1】:

    感谢您提供完整的代码示例。我看到你对你之前的question 评论说你在 Delphi XE2 中使用了 indy 10。

    问题可能是 indy 10 中的 SSL 身份验证有问题。Full explanation here 你可以做的是尝试获得 indy 组件的稳定版本。

    代码似乎没有错误,除了一些本可以被释放的资源;)。

    我真的希望在更新你的 indy 时你的问题能解决。

    【讨论】:

    • 我已经尝试从 svn Revision(4771) 更新 indy(10.5.8)。仍然面临同样的问题 401 未经授权。请帮助我@A1rPun。我正在尝试很多解决方案。
    • 嗨@A1rPun 你没有得到我的问题吗?请告诉我一些事情。我在 XML 中获得了自己的状态,但没有发布请帮助我。如果你有时间那么我想和你聊天。所以请联系我.....
    • 请任何人帮助我。直到现在我没有发布带有标题的 xml。一直面临 401 错误。我的回复是 4011340895781480BYE79V9AXB0[unauthorized]。 OAU:2j71bnoc4x5f|3b2f15bd-a2c8-474f-ae05-541dd9b76468|*01|*01:1340895531:PxhePw0/XHdvPz9cP3k/Px5WXz8=请帮帮我............ .
    猜你喜欢
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 2018-01-27
    相关资源
    最近更新 更多