53
53
$ client ->setRedirectUrl ($ _SESSION ['redirect_url ' ]);
54
54
// retrieve access token using code provided by LinkedIn
55
55
$ accessToken = $ client ->getAccessToken ($ _GET ['code ' ]);
56
- echo 'Access token: ' ;
56
+ h1 ( 'Access token ' ) ;
57
57
pp ($ accessToken ); // print the access token content
58
- echo 'Profile: ' ;
58
+ h1 ( 'Profile ' ) ;
59
59
// perform api call to get profile information
60
60
$ profile = $ client ->get (
61
61
'people/~:(id,email-address,first-name,last-name) '
83
83
// https://www.linkedin.com/company/devtestco
84
84
$ companyId = '2414183 ' ;
85
85
86
+ h1 ('Company information ' );
87
+ $ companyInfo = $ client ->get ('companies/ ' . $ companyId . ':(id,name,num-followers,description) ' );
88
+ pp ($ companyInfo );
89
+
90
+ h1 ('Sharing on company page ' );
86
91
$ companyShare = $ client ->post (
87
92
'companies/ ' . $ companyId . '/shares ' ,
88
93
[
104
109
]
105
110
);
106
111
pp ($ companyShare );
112
+
107
113
108
114
/*
109
115
// Returns {"serviceErrorCode":100,"message":"Not enough permissions to access media resource","status":403}
135
141
echo '<a href="/">Start over</a> ' ;
136
142
} else {
137
143
// define desired list of scopes
138
- $ scopes = Scope::getValues ();
144
+ $ scopes = [
145
+ Scope::READ_BASIC_PROFILE ,
146
+ Scope::READ_EMAIL_ADDRESS ,
147
+ Scope::MANAGE_COMPANY ,
148
+ Scope::SHARING ,
149
+ ];
139
150
$ loginUrl = $ client ->getLoginUrl ($ scopes ); // get url on LinkedIn to start linking
140
151
$ _SESSION ['state ' ] = $ client ->getState (); // save state for future validation
141
152
$ _SESSION ['redirect_url ' ] = $ client ->getRedirectUrl (); // save redirect url for future validation
@@ -151,3 +162,12 @@ function pp($anything)
151
162
{
152
163
echo '<pre> ' . print_r ($ anything , true ) . '</pre> ' ;
153
164
}
165
+
166
+ /**
167
+ * Add header
168
+ *
169
+ * @param string $h
170
+ */
171
+ function h1 ($ h ) {
172
+ echo '<h1> ' . $ h . '</h1> ' ;
173
+ }
0 commit comments