0

LinkedInユーザーのプロファイルとデータを共有するプログラムに取り組んでいます。同じようにDelphiXE2、OAuth、LinkedInAPIを使用しています。アクセストークンを取得できます。次に、ステータスを更新したいと思います。だから私のコードは

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の無許可に直面しています。私のques@A1rPunをチェックしてください。私を助けてください

4

1 に答える 1

0

完全なコード サンプルを提供していただきありがとうございます。Delphi XE2 で indy 10 を使用しているという以前の質問にコメントしたのを見ました。

問題は、indy 10 内の SSL 認証に何か問題がある可能性があります。完全な説明はこちらできることは、indy コンポーネントの安定したバージョンを取得しようとすることです。

解放された可能性のあるいくつかのリソースを除いて、コードにはエラーがないようです;)。

あなたのインディを更新するときにあなたの問題が解決することを本当に願っています.

于 2012-06-19T13:20:39.387 に答える