2016-12-13 19 views
0

アロハall、Google AppsスクリプトでLinkedin APIを使用していますか?

私は会社のページに投稿するためにlinkedinとgoogle appsスクリプトとの統合を作成します。

すべてのOAuth2の面で、良いですが、私はトークンを持っていますが、問題は体の要求で、見て:

var payload = {"visibility": {"code": "anyone"},"comment": "Testing a full company share!","content": {"submitted-­url": "https://www.google.com","title": "Test Share with Content","description": "content description","submitted‐image-­url": "https://www.wired.com/wp-content/uploads/2015/09/google-logo.jpg"}}; 
var headers = {Authorization': 'Bearer ' + Service.getAccessToken()}; 
var options = {method:'post',headers:headers,payload:payload,muteHttpExceptions:true}; 
var response = UrlFetchApp.fetch("https://api.linkedin.com/v1/companies/2414183/shares?format=json", options); 

私はTEST MY JSONリクエストのAPIGEEを使用するためのrequesは、良いです。いくつかのフォーラムで

[16-12-12 22:38:13:411 EST] { 
    "errorCode": 0, 
    "message": "Couldn't parse share document: error: Unexpected element: CDATA", 
    "requestId": "XNZ80U0LCX", 
    "status": 400, 
    "timestamp": 1481600293335 
} 

がHEARDER私はPUT SHOUDと言う:これは、サーバーの応答である

'Content-Typeの': 'アプリケーション/ JSON'、 '-LI-フォーマットをX': 'JSON'

しかしWHEN HEADER ON PUTこのコードは、サーバーエラーが:

[16-12-12 22:40:00:344 EST] { 
    "errorCode": 0, 
    "message": "Couldn't parse Json body: Unexpected character ('v' (code 118)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [email protected]; line: 1, column: 2]", 
    "requestId": "YQFPJKZTMC", 
    "status": 400, 
    "timestamp": 1481600400231 
} 

THANKS ALL

答えて

1
var payload = JSON.stringify(object): 

ない:

var payload = object; 

私もapplication/jsonにそれを設定し、ヘッダにコンテンツタイプを追加したい:

var options = { 
    'contentType': 'application/json', 
    'payload': JSON.stringify(payload) 
}; 
UrlFetchApp.fetch('https://www.example.com', options); 
0
ペイロードのはあなたには有効なJSONなどを提供する必要があります

1つの変更... LinkedInの開発者向けドキュメントパー:

あなたはJSON形式の体を提供することを選ぶ場合は、お使いのHTTPリクエストは、次のヘッダーが含まれていることを確認します

Content-Type: application/json 
x-li-format: json 

https://developer.linkedin.com/docs/share-on-linkedin

関連する問題